21 July 2024
File name variables in Windows batch

File name variables in Windows batch

27 September, 2018

If you need to manipulate (rename, move, etc) files in a windows batch, here are useful variables that can help with that:

set "filename=C:\Temp\Filename.txt"
For %%A in ("%filename%") do (
    echo full path: %%~fA
    echo directory: %%~dA
    echo path: %%~pA
    echo file name only: %%~nA
    echo extension only: %%~xA
    echo expanded path with short names: %%~sA
    echo attributes: %%~aA
    echo date and time: %%~tA
    echo size: %%~zA
    echo drive + path: %%~dpA
    echo name.ext: %%~nxA
    echo full path + short name: %%~fsA

 

ALT Technical

© ALT Technical. All rights reserved.