Categories:
Administration (10)
Adware Spyware (7)
Apache (10)
Bluetooth (125)
DOS Commands (1)
Edge (28)
General (2)
Internet Explorer (217)
Media Center (12)
Media Player (11)
Mozilla Firefox (18)
PHP (15)
Programming (8)
Security (4)
Silverlight (15)
Tips (17)
Tools (218)
Tutorials (5)
Windows 10 (166)
Windows 7 (636)
Windows 8 (1091)
Windows Phone (33)
Windows Server 2008 (165)
Windows Server 2012 (84)
Windows Server 2016 (23)
Windows Vista (52)
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, 3339👍, 1💬
Popular Posts:
Where to find tutorials on managing Windows 8 scheduled tasks? Here is a collection of tutorials on ...
How to remove msmsgs.exe from the startup application list to gain performance and reduce security r...
What is the startup program "QuickSet MFC Application - quickset.exe" on my Windows 8 computer? Can ...
How to export Windows services to a text file? If you want to export services that are currently con...
the computer detect the microphone plugged in, but it's not working with any App. or Desktop soft we...