Saved Bookmarks
| 1. |
Solve : Manipulating file/folder location in BAT files? |
|
Answer» All, This location is stored in the %1 value as (example) X:\folder1\folder2\longfoldername3\file.ext. I want to separate the folder location of the file and the filename itself. How can I grab X:\folder1\folder2\longfoldername3 as one variable and file.ext as another variable? See FOR /? If %1 is a filename, whether just the filename e.g. afile.ext or a path and filename eg d:\folder\subfolder\afile.ext then... %~1 - expands %1 removing any surrounding quotes (") %~f1 - expands %1 to a fully qualified path name %~d1 - expands %1 to a drive letter only %~p1 - expands %1 to a path only %~n1 - expands %1 to a file name only %~x1 - expands %1 to a file extension only %~s1 - expanded path contains short names only %~a1 - expands %1 to file attributes of file %~t1 - expands %1 to date/time of file %~z1 - expands %1 to size of file These can be combined... N.B. The file need not exist, an imaginary filename is still processed just the same, although items impossible to resolve, such as size, date/time, etc expand to blanks. This is a folder... Quote S:\Backup\Test\stringlen>dir This is filestuff.bat Quote @echo off This is the output of the command:- filestuff "sfor.cmd" ... Quote parameter passed %1 is "sfor.cmd" Holy crap thank you... |
|