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, ∼6615🔥, 1💬
Popular Posts:
How to remove BTTray.exe from startup program list? If you are not using any bluetooth devices, you ...
What is "User Profile Service" in my Windows XP service list? And how is "User Profile Service" serv...
How to download Windows 7 Service Pack 1 (SP1)? Windows 7 Service Pack 1 (SP1) is an update for all ...
I have a problem wiht the Drivers Video Card, I have a laptop HP dv6448se and the video card are a N...
How to add a hyperlink to connect a keyword to another slide? I want to have clickable links to help...