I have a batch file which takes as an argument a file path
set filePath = %1
Now, lets say the file path is: C:\Temp\Folder, I want to set the Folder in a new variable. How can I do that?
I search on the web and all solutions are something like this:
for %%A in (%filePath%) do set last=%%A
but this works only for string with with spaces.
You can extract
FolderfromC:\Temp\Folderby applying the~nmodifier to%1:If the last item may contain
., use~nxinstead:The
~nmodifier applies to a positional parameter or a loop variable and extracts the last name from the path specified by that parameter or variable. The~xmodifier extracts the extension of the last name (the part starting from the last.). Accordingly,~nxextracts both the (last) name and the extension.