テストスクリプト
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
:: courtesy of https://ss64.com/nt/syntax-args.html @echo off echo %%1 : as it is echo %%1=%1 echo. echo %%~f1 : Fully quolified path echo %%~f1=%~f1 echo. echo %%~d1 : Drive letter echo %%~d1=%~d1 echo. echo %%~p1 : Path only echo %%~p1=%~p1 echo. echo %%~n1 : file Name without file extension echo %%~n1=%~n1 echo. echo %%~x1 : file eXtension only echo %%~x1=%~x1 echo. echo %%~s1 : Short 8.3 name echo %%~s1=%~s1 echo. echo %%~1 : removing any surrounding quotes (") echo %%~1=%~1 echo. echo %%~a1 : Display the file attributes of %%1 echo %%~a1=%~a1 echo. echo %%~t1 : Display the date/time of %%1 echo %%~t1=%~t1 echo. echo %%~z1 : Display the file size of %%1 echo %%~z1=%~z1 echo. echo %%~$PATH:1 : Search the PATH environment variable and expand %%1 to the fully qualified name of the first match found echo %%~$PATH:1=%~$PATH:1 echo. |
実演
testbat.bat aaa
%1 : as it is
%1=aaa
%~f1 : Fully quolified path
%~f1=C:\local\msys2\home\skYjennr\gitdev\bat\src\aaa
%~d1 : Drive letter
%~d1=C:
%~p1 : Path only
%~p1=\local\msys2\home\skYjennr\gitdev\bat\src\
%~n1 : file Name without file extension
%~n1=aaa
%~x1 : file eXtension only
%~x1=
%~s1 : Short 8.3 name
%~s1=C:\local\msys2\home\skYjennr\gitdev\bat\src\aaa
%~1 : removing any surrounding quotes (“)
%~1=aaa
%~a1 : Display the file attributes of %1
%~a1=
%~t1 : Display the date/time of %1
%~t1=
%~z1 : Display the file size of %1
%~z1=
%~$PATH:1 : Search the PATH environment variable and expand %1 to the fully qualified name of the first match found
%~$PATH:1=
WScript.Arguments.Count=1
WScript.Arguments(0)=aaa
testbat.bat “aaa”
%1 : as it is
%1=”aaa”
%~f1 : Fully quolified path
%~f1=C:\local\msys2\home\skYjennr\gitdev\bat\src\aaa
%~d1 : Drive letter
%~d1=C:
%~p1 : Path only
%~p1=\local\msys2\home\skYjennr\gitdev\bat\src\
%~n1 : file Name without file extension
%~n1=aaa
%~x1 : file eXtension only
%~x1=
%~s1 : Short 8.3 name
%~s1=C:\local\msys2\home\skYjennr\gitdev\bat\src\aaa
%~1 : removing any surrounding quotes (“)
%~1=aaa
%~a1 : Display the file attributes of %1
%~a1=
%~t1 : Display the date/time of %1
%~t1=
%~z1 : Display the file size of %1
%~z1=
%~$PATH:1 : Search the PATH environment variable and expand %1 to the fully qualified name of the first match found
%~$PATH:1=
WScript.Arguments.Count=1
WScript.Arguments(0)=aaa
testbat.bat “%LOCALAPPDATA%\CrashDumps”
%1 : as it is
%1=”C:\Users\skYjennr\AppData\Local\CrashDumps”
%~f1 : Fully quolified path
%~f1=C:\Users\skYjennr\AppData\Local\CrashDumps
%~d1 : Drive letter
%~d1=C:
%~p1 : Path only
%~p1=\Users\skYjennr\AppData\Local\
%~n1 : file Name without file extension
%~n1=CrashDumps
%~x1 : file eXtension only
%~x1=
%~s1 : Short 8.3 name
%~s1=C:\Users\skYjennr\AppData\Local\CRASHD~1
%~1 : removing any surrounding quotes (“)
%~1=C:\Users\skYjennr\AppData\Local\CrashDumps
%~a1 : Display the file attributes of %1
%~a1=d—-c—–
%~t1 : Display the date/time of %1
%~t1=2021/07/01 15:59
%~z1 : Display the file size of %1
%~z1=0
%~$PATH:1 : Search the PATH environment variable and expand %1 to the fully qualified name of the first match found
%~$PATH:1=C:\Users\skYjennr\AppData\Local\CrashDumps
WScript.Arguments.Count=1
WScript.Arguments(0)=C:\Users\skYjennr\AppData\Local\CrashDumps
testbat.bat “C:\aa bb cc\dd ee\my file.zip”
%1 : as it is
%1=”C:\aa bb cc\dd ee\my file.zip”
%~f1 : Fully quolified path
%~f1=C:\aa bb cc\dd ee\my file.zip
%~d1 : Drive letter
%~d1=C:
%~p1 : Path only
%~p1=\aa bb cc\dd ee\
%~n1 : file Name without file extension
%~n1=my file
%~x1 : file eXtension only
%~x1=.zip
%~s1 : Short 8.3 name
%~s1=C:\aa bb cc\dd ee\my file.zip
%~1 : removing any surrounding quotes (“)
%~1=C:\aa bb cc\dd ee\my file.zip
%~a1 : Display the file attributes of %1
%~a1=
%~t1 : Display the date/time of %1
%~t1=
%~z1 : Display the file size of %1
%~z1=
%~$PATH:1 : Search the PATH environment variable and expand %1 to the fully qualified name of the first match found
%~$PATH:1=
WScript.Arguments.Count=1
WScript.Arguments(0)=C:\aa bb cc\dd ee\my file.zip
testbat.bat notepad.exe
%1 : as it is
%1=notepad.exe
%~f1 : Fully quolified path
%~f1=C:\local\msys2\home\skYjennr\gitdev\bat\src\notepad.exe
%~d1 : Drive letter
%~d1=C:
%~p1 : Path only
%~p1=\local\msys2\home\skYjennr\gitdev\bat\src\
%~n1 : file Name without file extension
%~n1=notepad
%~x1 : file eXtension only
%~x1=.exe
%~s1 : Short 8.3 name
%~s1=C:\local\msys2\home\skYjennr\gitdev\bat\src\notepad.exe
%~1 : removing any surrounding quotes (“)
%~1=notepad.exe
%~a1 : Display the file attributes of %1
%~a1=
%~t1 : Display the date/time of %1
%~t1=
%~z1 : Display the file size of %1
%~z1=
%~$PATH:1 : Search the PATH environment variable and expand %1 to the fully qualified name of the first match found
%~$PATH:1=C:\Windows\System32\notepad.exe
WScript.Arguments.Count=1
WScript.Arguments(0)=notepad.exe