Tag Archives: bat

バッチファイルの引数を色々変換

テストスクリプト

実演

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