Phi*_*lip 5 batch batch-file cmd.exe
我正在运行以下命令,
@echo off
cls
for /r D:\ %%a in (*) do if "%%~nxa"=="new.txt" set p=%%~dpnxa
if defined p (
echo File found its path - %p%
pause
) else (
echo File not found !
pause
)
Run Code Online (Sandbox Code Playgroud)
它将搜索new.txt整个驱动器D:文件夹和子文件夹中命名的文件作为最终结果,它会将该文件的完整路径显示new.txt为如下输出,(假设new.txt文件位于D:\folder\)
File found and its path - D:\folder\new.txt
Press any key to continue . . .
Run Code Online (Sandbox Code Playgroud)
new.txt但问题是,如果驱动器中不同文件夹或子文件夹中有多个同名文件D:,则仅显示一个路径输出。
我的需要是,想要显示new.txt驱动器上具有相同名称的所有文件路径D:,如下输出,
预期输出需要这样,
Files found : 4
Files Paths :
1 - D:\folder\new.txt
2 - D:\new folder\new.txt
3 - D:\files\new.txt
4 - D:\folder\new\new.txt
Run Code Online (Sandbox Code Playgroud)
请帮忙..提前谢谢。
new.txt驱动器上具有相同名称的所有文件路径D:预期输出:
Run Code Online (Sandbox Code Playgroud)Files found : 4 Files Paths : 1 - D:\folder\new.txt 2 - D:\new folder\new.txt 3 - D:\files\new.txt 4 - D:\folder\new\new.txt
使用以下批处理文件:
Files found : 4
Files Paths :
1 - D:\folder\new.txt
2 - D:\new folder\new.txt
3 - D:\files\new.txt
4 - D:\folder\new\new.txt
Run Code Online (Sandbox Code Playgroud)