Batch Variables in Windows
Batch files in windows can be quite useful, especially when you know how to do things with them. I created and use this particular file on a fairly frequent basis to find out which percent variables to do with files do what (useful for passing files around and keeping or changing their name/extension). Not sure about availability on Windows versions below Vista, try it!
How to use it:
- Download this zip file with the batch file in
- Extract it and put batch_variables.bat wherever you feel like putting it
- Now when you want to find out about the particular variable values for a file, just drag it, and drop it on batch_variables.bat
- Hopefully the window shown above will open and display the values
- Leave a comment about it, or view comments that have been left
The Variables
They all start with %~
Then there's a letter
And then its either a zero for the batch file itself or a one for the file you fed it
| The Current File | ||
| Percent Code | Result | Example |
| %~d0 | Drive | H: |
| %~p0 | Path (No Drive) | \Notes\ |
| %0 | Full Quoted Path | "H:\Notes\batch_variables.bat" |
| %~f0 | Full Path | H:\Notes\batch_variables.bat |
| %~s0 | 8.3 Short Path | H:\Notes\BATCH_~1.bat |
| %~n0 | Filename (No Extension) | batch_variables |
| %~x0 | File Extension | .bat |
| %~t0 | Modified Time | 10/12/2009 05:46 |
| %~z0 | File Size (bytes) | 1233 |
| The Input File | ||
| Percent Code | Result | Example |
| %~d1 | Drive | C: |
| %~p1 | Path (No Drive) | \Program Files (x86)\Mozilla Firefox\ |
| %1 | Full Quoted Path | "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" |
| %~f1 | Full Path | C:\Program Files (x86)\Mozilla Firefox\firefox.exe |
| %~s1 | 8.3 Short Path | C:\PROGRA~2\MOZILL~1\firefox.exe |
| %~n1 | Filename (No Extension) | firefox |
| %~x1 | File Extension | .exe |
| %~t1 | Modified Time | 28/10/2008 14:46 |
| %~z1 | File Size (bytes) | 908280 |
Don't want to download it? Here:
@echo OFF rem -- By Lewis rem -- zoril.co.uk echo -------------- echo - THIS FILE - echo -------------- echo. rem - drive of file echo [ Drive ][ %%~d0 ] %~d0 rem - path of file [ no filename or drive ] echo [ Path ][ %%~p0 ] %~p0 rem - path of file echo [ Path ][ %%0 ] %0 echo [ Path ][ %%~f0 ] %~f0 rem - short path of file echo [ Short ][ %%~s0 ] %~s0 rem - name of file [ no extension ] echo [ Name ][ %%~n0 ] %~n0 rem - extension of file echo [ Exten ][ %%~x0 ] %~x0 rem - modified time of file echo [ Time ][ %%~t0 ] %~t0 rem - bytesize of file echo [ Size ][ %%~z0 ] %~z0 echo. echo. echo -------------- echo - INPUT FILE - echo -------------- echo. rem - drive of file echo [ Drive ][ %%~d1 ] %~d1 rem - path of file [ no filename or drive ] echo [ Path ][ %%~p1 ] %~p1 rem - path of file echo [ Path ][ %%1 ] %1 echo [ Path ][ %%~f1 ] %~f1 rem - short path of file echo [ Short ][ %%~s1 ] %~s1 rem - name of file [ no extension ] echo [ Name ][ %%~n1 ] %~n1 rem - extension of file echo [ Exten ][ %%~x1 ] %~x1 rem - modified time of file echo [ Time ][ %%~t1 ] %~t1 rem - bytesize of file echo [ Size ][ %%~z1 ] %~z1 echo. echo. echo. rem a line with an a in echo %~a1 pause > nul
[27/11/2009]