本文介绍了在批处理文件中,如何从文件路径获取文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个批处理文件,要求用户输入文件路径.稍后在文件中,我只想从路径中隔离文件名和扩展名,即最后一个'\'之后的任何内容.
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=???
我需要将FILENAME设置为什么才能使其等于"My SpreadSheet.xls"?
What do i need to set FILENAME to in order for it to equal 'My SpreadSheet.xls'?
希望这很简单.谢谢!
推荐答案
@echo off
set FILEPATH=\\srv-01\My Docs\Templates\My SpreadSheet.xls
for /F "delims=" %%A in ("%FILEPATH%") do set "FILEPATH=%%~nxA"
echo.%FILEPATH%
这篇关于在批处理文件中,如何从文件路径获取文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!