S
Stewart Halyard
I am writing a script in which I must validate the folder
of a file specification entered on the command line. For
example, if my batch file is called myBatch.bat and the user
runs:
myBatch c:\myProgs\MyLogs\*.log
I must validate the folder c:\myProgs\MyLogs\.
I can do this only when the folder name contains no spaces,
because when I query for the NULL device when the folder name
is in quotes, IF NOT EXIST returns true.
Here's some code that works when there are no spaces in the path:
REM *** Works only with no spaces in path ***
SET theFolder=%~dp1
IF NOT EXIST %theFolder%nul (
ECHO Invalid folder: "%theFolder%"
)
If I specifiy a folder with spaces, the above code doesn't work
because it thinks there are more than one command in the IF
statement. So I add quotes around the folder name:
REM *** Never works because IF NOT EXIST always returns true ***
SET theFolder=%~dp1
IF NOT EXIST "%theFolder%nul" (
ECHO Invalid folder: "%theFolder%"
)
The echo statement is always executed. Apparently, Windows 2000
can't tell that I'm querying for the NULL device when there are quotes
around the path.
For reference on batch parameters like %~dp1, see:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx
Any help would be most appreciated!
Jay
of a file specification entered on the command line. For
example, if my batch file is called myBatch.bat and the user
runs:
myBatch c:\myProgs\MyLogs\*.log
I must validate the folder c:\myProgs\MyLogs\.
I can do this only when the folder name contains no spaces,
because when I query for the NULL device when the folder name
is in quotes, IF NOT EXIST returns true.
Here's some code that works when there are no spaces in the path:
REM *** Works only with no spaces in path ***
SET theFolder=%~dp1
IF NOT EXIST %theFolder%nul (
ECHO Invalid folder: "%theFolder%"
)
If I specifiy a folder with spaces, the above code doesn't work
because it thinks there are more than one command in the IF
statement. So I add quotes around the folder name:
REM *** Never works because IF NOT EXIST always returns true ***
SET theFolder=%~dp1
IF NOT EXIST "%theFolder%nul" (
ECHO Invalid folder: "%theFolder%"
)
The echo statement is always executed. Apparently, Windows 2000
can't tell that I'm querying for the NULL device when there are quotes
around the path.
For reference on batch parameters like %~dp1, see:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx
Any help would be most appreciated!
Jay