Collections:
Other Resources:
Get Batch Parameter as File Path
How to get path name components of a batch file parameter? A file name is passed as the parameter.
✍: FYIcenter.com
If a batch parameter represents a file name, you can use batch parameter modifiers on %1, %2 or others, to get its file patch components.
Here is a batch file, Batch-Parameter-Modifiers.bat, that dumps the %1 parameter with different modifiers:
@echo off rem Batch-Parameter-Modifiers.bat - Show components of a batch parameter echo 1 = %1 echo ~1 = %~1 echo ~f1 = %~f1 echo ~d1 = %~d1 echo ~p1 = %~p1 echo ~n1 = %~n1 echo ~x1 = %~x1 echo ~s1 = %~s1 echo ~a1 = %~a1 echo ~t1 = %~t1 echo ~z1 = %~z1 echo ~$PATH:1 = %~$PATH:1 echo ~dp1 = %~dp1 echo ~pd1 = %~pd1 echo ~nx1 = %~nx1 echo ~dp$PATH:1 = %~dp$PATH:1 echo ~ftza1 = %~ftza1
If you run the above batch file with an absolute file name, you get the following output:
C:\fyicenter>Batch-Parameter-Modifiers.bat "\Program Files\7-Zip\7z.exe" 1 = "\Program Files\7-Zip\7z.exe" ~1 = \Program Files\7-Zip\7z.exe ~f1 = C:\Program Files\7-Zip\7z.exe ~d1 = C: ~p1 = \Program Files\7-Zip\ ~n1 = 7z ~x1 = .exe ~s1 = C:\PROGRA~1\7-Zip\7z.exe ~a1 = --a------ ~t1 = 10/04/2016 09:51 AM ~z1 = 446976 ~$PATH:1 = C:\Program Files\7-Zip\7z.exe ~dp1 = C:\Program Files\7-Zip\ ~pd1 = C:\Program Files\7-Zip\ ~nx1 = 7z.exe ~dp$PATH:1 = C:\Program Files\7-Zip\ ~ftza1 = --a------ 10/04/2016 09:51 AM 446976 C:\Program Files\7-Zip\7z.exe
If you run the above batch file with a program file name, if may find the path name for you in the %PATH variable:
C:\fyicenter>Batch-Parameter-Modifiers.bat java.exe 1 = java.exe ~1 = java.exe ~f1 = C:\fyicenter\java.exe ~d1 = C: ~p1 = \fyicenter\ ~n1 = java ~x1 = .exe ~s1 = C:\FYICEN~1\java.exe ~a1 = ~t1 = ~z1 = ~$PATH:1 = C:\ProgramData\Oracle\Java\javapath\java.exe ~dp1 = C:\fyicenter\ ~pd1 = C:\fyicenter\ ~nx1 = java.exe ~dp$PATH:1 = C:\ProgramData\Oracle\Java\javapath\ ~ftza1 = C:\fyicenter\java.exe
If you run the above batch file with a text message, the output is not that useful:
C:\fyicenter>Batch-Parameter-Modifiers.bat "Hello world!" 1 = "Hello world!" ~1 = Hello world! ~f1 = C:\fyicenter\Hello world! ~d1 = C: ~p1 = \fyicenter\ ~n1 = Hello world! ~x1 = ~s1 = C:\FYICEN~1\Hello world! ~a1 = ~t1 = ~z1 = ~$PATH:1 = ~dp1 = C:\fyicenter\ ~pd1 = C:\fyicenter\ ~nx1 = Hello world! ~dp$PATH:1 = ~ftza1 = C:\fyicenter\Hello world!
⇒ What Is "for" Loop Parameter
⇐ Get Batch File Path Name Components
2022-03-06, 4937🔥, 1💬
Popular Posts:
How do I know which version of Internet Explorer (IE) is on my computer? If you want to know which v...
How to uninstall ActivePerl 5.8.8.820? If for some reason you want to uninstall ActivePerl from your...
What files are stored in the "C:\Users\<userid >\AppData\Local\M icrosoft\Windows\Tempor. ..
What is EvtEng.exe process - Intel Wireless EvtEng Module? Process EvtEng.exe is related to your wir...
What is Shockware Flash Object - Download Program Files (DPF)? Shockware Flash Object is a Download ...