问题
I have a batch file that requires the user to enter a file path. Later on in the file I want to isolate just the filename and extention from the path, ie anything after the last '\'.
set FILEPATH=\\srv-01\My Docs\Templates\My SpreadSheet.xls
...
set FILENAME=???
What do i need to set FILENAME to in order for it to equal 'My SpreadSheet.xls'?
Hopefully this is fairly simple to do. Thanks!
回答1:
@echo off
set FILEPATH=\\srv-01\My Docs\Templates\My SpreadSheet.xls
for /F "delims=" %%A in ("%FILEPATH%") do set "FILEPATH=%%~nxA"
echo.%FILEPATH%
来源:https://stackoverflow.com/questions/11104433/in-a-batch-file-how-do-i-get-a-file-name-from-a-file-path