我需要扫描驱动器并列出仅包含一个文件的所有文件夹,该文件名为“Thumbs v0.1.db”。我拼凑了以下代码,但它似乎不起作用。批处理文件要么过早退出,要么在没有列出任何此类子目录的情况下完成!如果有人能指出问题,我将不胜感激。
@echo off
SET /P folder="Please enter root directory to seach in: "
SET writefile="C:\Users\MYNAME\Desktop\Thumbs.txt"
SET tmp="C:\Users\MYNAME\Desktop\rowcounttmp"
Echo Searching for directories, please wait...
echo Thumbs v0.1.db-only directories in %folder% > %writefile%
cd /D %folder%
for /d /r %1 %%A in (.) do (
dir /a /b "%%~fA" 2>nul | find /c /v "~StringWhichWillNotAppear~" > %tmp%
set var=<%tmp%
if [%var%] == 1 dir /a /b "%%~fA" 2>nul | findstr /i "Thumbs v0.1.db" >nul && echo %%~fA >> %writefile%
)
del %tmp%
Pause
谢谢
编辑:
感谢@peter-wright,我现在有了这个:我是否错误地执行了他的建议?某些文件路径(特别是我试图扫描的只读驱动器)似乎崩溃了,但仍然没有结果出现。
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
Color 0A
SET /P folder="Please enter root directory to seach in: "
SET writefile="C:\Users\MYNAME\Desktop\Thumbs.txt"
SET tempfile="C:\Users\MYNAME\Desktop\rowcounttmp"
Echo Searching for directories, please wait...
echo Thumbs v0.1.db only directories in %folder% > %writefile%
cd /D %folder%
for /d /r %1 %%A in (.) do (
dir /a /b "%%~fA" 2>nul | find /c /v "~StringWhichWillNotAppear~" > %tempfile%
set var=<%tempfile%
if !var! == 1 dir /a /b "%%~fA" 2>nul | findstr /i "Thumbs v0.1.db" >nul && echo %%~fA >> %writefile%
)
del %tempfile%
Pause