我正在执行以下命令,
@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
)
它将搜索new.txt
整个驱动器D:
文件夹和子文件夹上命名的文件作为最终结果,并显示该文件的完整路径,new.txt
如下所示(以假设new.txt
文件位于D:\folder\
)
File found and its path - D:\folder\new.txt
Press any key to continue . . .
但是问题是,如果在不同文件夹或子文件夹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
请帮助。
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
使用以下批处理文件:
@echo off
setlocal
rem change to the correct directory
cd /d d:\
rem count the files
dir /b new.txt /s 2> nul | find "" /v /c > %temp%\count
set /p _count=<%temp%\count
rem cleanup
del %temp%\count
rem output the number of files
echo Files found : %_count%
rem list the files
echo Files Paths :
dir /b new.txt /s
endlocal
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句