%1
是第一個命令行參數。
C:\Users\User>if exist c:\windows echo windows exist
windows exist
C:\Users\User>if exist c:\windows1 echo windows exist
C:\Users\User>
而且有些標點符號
& seperates commands on a line.
&& executes this command only if previous command's errorlevel is 0.
|| (not used above) executes this command only if previous command's errorlevel is NOT 0
> output to a file
>> append output to a file
< input from a file
| output of one command into the input of another command
^ escapes any of the above, including itself, if needed to be passed to a program
" parameters with spaces must be enclosed in quotes
+ used with copy to concatinate files. E.G. copy file1+file2 newfile
, used with copy to indicate missing parameters. This updates the files modified date. E.G. copy /b file1,,
%variablename% a inbuilt or user set environmental variable
!variablename! a user set environmental variable expanded at execution time, turned with SelLocal EnableDelayedExpansion command
%<number> (%1) the nth command line parameter passed to a batch file. %0 is the batchfile's name.
%* (%*) the entire command line.
%<a letter> or %%<a letter> (%A or %%A) the variable in a for loop. Single % sign at command prompt and double % sign in a batch file.
的列表,如果你想知道一個目錄或文件。
@Echo off
pushd %1 >nul 2>&1
If errorlevel 0 if not errorlevel 1 Echo %~nx1 is a folder
If errorlevel 1 Echo %~nx1 is not a folder
Popd
If /i "%cmdcmdline:~0,6%"=="cmd /c" pause
自從我上次寫了一個DOS/Windows shell腳本(這是MS shell的東西,對嗎?)以來,我已經年齡增長了,所以我不記得很多東西。 %1是腳本的第一個參數,例如如果你運行'myscript.bat testDir',那麼%1將是「testDir」,我懷疑你的'SET'行;爲了調試的目的,我會在那裏包含一個'echo%t'行來檢查變量的值是否正確 – GergelyPolonkai
[檢查一個文件夾是否存在使用.bat文件]可能的重複(http://stackoverflow.com/questions/21033801/checking-if-a-folder-exists-using-a-bat-file) – aschipfl