Friday, 6 September 2013

DOS batch file: Get full path and long file name from short file name

DOS batch file: Get full path and long file name from short file name

I have an nice console file manager (eXtreme by Senh Liu), it passes short
path/filenames as variables to a menu.bat.
How can I generate a full folder name + long file name?
Example:
input variable = "P:\MYPROG~1\SHELLS\ZBACKUP\REFSTO~1.BAL"
target variable = "P:\MyPrograms\SHELLS\zBackup\RefsToMyData.bal"
I have tried the following:
SET my_file=%~2
echo %my_file%
Produces: "P:\MYPROG~1\SHELLS\ZBACKUP\REFSTO~1.BAL"
FOR /F "tokens=* USEBACKQ" %%F IN (dir /B %2) DO SET my_file=%%~fF
echo %my_file%
Produces: "P:\MYPROG~1\SHELLS\zBackup\RefsToMyData.bal"
FOR /F "tokens=* USEBACKQ" %%F IN (dir /B %2) DO SET my_file=%%~dpnxF
echo %my_file%
Produces: "P:\MYPROG~1\SHELLS\zBackup\RefsToMyData.bal"
Thanks in advance.
Kind Regards
Gavin

No comments:

Post a Comment