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!

Screenshot

How to use it:
  1. Download this zip file with the batch file in
  2. Extract it and put batch_variables.bat wherever you feel like putting it
  3. 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
  4. Hopefully the window shown above will open and display the values
  5. 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 CodeResultExample
%~d0DriveH:
%~p0Path (No Drive)\Notes\
%0Full Quoted Path"H:\Notes\batch_variables.bat"
%~f0Full PathH:\Notes\batch_variables.bat
%~s08.3 Short PathH:\Notes\BATCH_~1.bat
%~n0Filename (No Extension)batch_variables
%~x0File Extension.bat
%~t0Modified Time10/12/2009 05:46
%~z0File Size (bytes)1233
 
The Input File
Percent CodeResultExample
%~d1DriveC:
%~p1Path (No Drive)\Program Files (x86)\Mozilla Firefox\
%1Full Quoted Path"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
%~f1Full PathC:\Program Files (x86)\Mozilla Firefox\firefox.exe
%~s18.3 Short PathC:\PROGRA~2\MOZILL~1\firefox.exe
%~n1Filename (No Extension)firefox
%~x1File Extension.exe
%~t1Modified Time28/10/2008 14:46
%~z1File 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]