qq_43663201
ArsiIksait
采纳率100%
2020-03-19 09:44

批处理怎么全盘查找指定文件夹并获取其路径?[已解决,但是方法很萌新,不喜勿喷]

已采纳

BAT脚本如下:

@ECHO OFF
COLOR 0A
MD C:\Users\Administrator\Desktop\DIR_PACH_LOGS
SET P=C:\Users\Administrator\Desktop\DIR_PACH_LOGS
SET O1=C:\Users\Administrator\Desktop
ECHO "正在全盘查找Steam安装目录,请耐心等待!"
DIR /s /b A:\steam.exe>%P%\PACH_1.log
DIR /s /b B:\steam.exe>%P%\PACH_2.log
DIR /s /b C:\steam.exe>%P%\PACH_3.log
DIR /s /b D:\steam.exe>%P%\PACH_4.log
DIR /s /b E:\steam.exe>%P%\PACH_5.log
DIR /s /b F:\steam.exe>%P%\PACH_6.log
DIR /s /b G:\steam.exe>%P%\PACH_7.log
DIR /s /b H:\steam.exe>%P%\PACH_8.log
DIR /s /b I:\steam.exe>%P%\PACH_9.log
DIR /s /b J:\steam.exe>%P%\PACH_10.log
DIR /s /b K:\steam.exe>%P%\PACH_11.log
DIR /s /b L:\steam.exe>%P%\PACH_12.log
DIR /s /b M:\steam.exe>%P%\PACH_13.log
DIR /s /b N:\steam.exe>%P%\PACH_14.log
DIR /s /b O:\steam.exe>%P%\PACH_15.log
DIR /s /b P:\steam.exe>%P%\PACH_16.log
DIR /s /b Q:\steam.exe>%P%\PACH_17.log
DIR /s /b R:\steam.exe>%P%\PACH_18.log
DIR /s /b S:\steam.exe>%P%\PACH_19.log
DIR /s /b T:\steam.exe>%P%\PACH_20.log
DIR /s /b U:\steam.exe>%P%\PACH_21.log
DIR /s /b V:\steam.exe>%P%\PACH_22.log
DIR /s /b W:\steam.exe>%P%\PACH_23.log
DIR /s /b X:\steam.exe>%P%\PACH_24.log
DIR /s /b Y:\steam.exe>%P%\PACH_25.log
DIR /s /b Z:\steam.exe>%P%\PACH_26.log
ECHO "查找完毕!进入下一步操作!"
ping 127.0.0.1 -n 3 >nul
ECHO "合并日志并获取路径变量....."
COPY %P%\*.log %O1%\ALL_PACH.log
ECHO "等待文件生成....."
ping 127.0.0.1 -n 8 >nul
for /f "delims=" %%i in (%O1%\ALL_PACH.log) do (
    set APL=%%~i
    goto Next
)

:Next
SET APL=%APL:\steam.exe=%
ECHO "成功!开始操作!"

===这是一个笨办法,不喜勿喷===
把steam.exe换成你要查找的文件,多余的ECHO命令可以删掉。
" SET APL=%APL:\steam.exe=% "(代码片里倒数第2行)这个要是找文件全路径的话就删掉,否则%APL%的输出结果是该文件所在的文件夹全路径。
开头大写的是自己写的,小写的是网上查的,稍微修改了一下。

百度上搜不着用CMD全盘查找文件路径的,不知道为啥,只有全盘查找文件夹路径的。我把我写的放出来分享一下吧,说不定会有人看见,拿去简化。
——ArsiIksait最后编辑于2020/04/02 20:00:00

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答