WHEREIS.BAS Problem Under MS-DOS 4.x and 5.0 (62202)






This article was previously published under Q62202

SUMMARY

The sample program WHEREIS.BAS searches for the location of a specific file on disk. WHEREIS uses the Basic SHELL statement to perform a DOS DIR command and redirects the results to a file that WHEREIS.BAS later scans for the file it is searching for.

Under MS-DOS versions 4.0, 4.01, an 5.0, the WHEREIS.BAS program SHELL command does not function correctly. The path specification string passed to the DOS DIR command from WHEREIS ends with a backslash character, resulting in a DIR command something like the following:
   DIR C:\QB45\x\ 
				
This form of the DIR command returns a list of files in the QB45 directory when used under MS-DOS 3.x and earlier. Under MS-DOS 4.0, 4.01, and 5.0, this command fails with the error message "Invalid directory." Removing the trailing backslash allows the DIR command to operate under MS-DOS 4.x and 5.0.

This information applies to the WHEREIS.BAS program shipped with the following products: Microsoft QuickBasic versions 4.0, 4.0b, 4.5 for MS-DOS; Microsoft Basic Professional Development System (PDS) versions 7.0 and 7.1 for MS-DOS; and Microsoft Basic Compiler versions 6.0 and 6.0b for MS-DOS.

MORE INFORMATION

To correct WHEREIS.BAS to operate under MS-DOS 4.0, 4.01, and 5.0, you need to add several lines to the ScanDir SUBprogram in WHEREIS.BAS.

In the original version of WHEREIS.BAS, line 12 of the ScanDir SUB reads as follows:
   SHELL "DIR " + PathSpec$ + " > " + TempSpec$
				
To remove the trailing backslash from the string PathSpec$, replace the line above with the following:
   StripPath$ = PathSpec$
   IF RIGHT$(StripPath$,1) = "\" AND LEN(StripPath$) > 1 THEN
     StripPath$ = LEFT$(StripPath$, LEN(StripPath$) - 1)
   END IF
   SHELL "DIR " + StripPath$ + " > " + TempSpec$
				

Modification Type: Minor Last Reviewed: 1/8/2003
Keywords: KB62202