只保存具有完整目录的.txt文件中的文件夹的名称(批处理)

(我没有用这个东西做一个批次)

我有一个名为"worldcopy2.txt"里面有一个完整的目录的文件:

 C:\Users\Robert\Desktop\myworld2 

而且我想创build一个batch file来改变.txt里面只有当前目录的最后一个文件夹的名字。 例如:

如果.txt文件显示C:\Users\Robert\Desktop\funinside ,则该批处理必须将.txt更改为仅在funinside说。

必须与所有目录一起工作。

翻译谷歌翻译。

我试过这个:

 @echo off setlocal REM read a full path from file type worldcopy2.txt for /f %%F in (worldcopy2.txt) do set x=%%F REM extract last path component and write it back to file for %%P in ("%x%") do echo %%~nP> worldcopy2.txt type worldcopy2.txt 

测试后放弃type worldcopy2.txt语句。 这个背后的想法是将路径视为完全合格的文件名,并让for循环提取名称。 请注意,如果文件夹名称包含一个点(“。”),将会失败。