我正在尝试使用批处理文件计算根目录中的文件夹和文件数。
批处理文件计算
的数量我遇到的问题是它成功提供了文件夹的输出,但在文件的情况下,代码无法检测被拒绝的文件。否则它工作正常。
以下是代码:
@echo off
setlocal EnableExtensions EnableDelayedExpansion
for /F "delims=" %%x in (D:\Download\new.txt) do (
for /D %%a in ("%%x") do (
for /F "tokens=1,2,3 delims= " %%i in ('dir /A /S "%%x\*" ^| %SystemRoot%\System32\find.exe /I "bytes"') do (
if "%%j"=="File(s)" (
set "numfiles=%%i"
) else (
for /F %%a in ('dir /AD /B /S "%%x\*" ^| %SystemRoot%\System32\find.exe /C /V ""') do set "numfolders=%%a"
)
)
set "size=0"
for /f "tokens=3,5" %%b in ('dir /A /-C /S /W "%%~fa\*" 2^>nul ^| %SystemRoot%\System32\findstr.exe /B /C:" "') do if "%%~c"=="" set "status=Unlocked" & set "size=%%~b"
set /A size/=1024
echo %%a,%%~nxa,!size!,%%~ta,!numfolders!,!numfiles!
set "deniedFolderCount=0"
set "okFolderCount=0"
set "emptyFolderCount=0"
set "deniedFileCount=0"
set "okFileCount=0"
set "emptyFileCount=0"
for /F "delims=" %%m in ('dir /B /S "%%~fx\*"') do (
for %%Z In ("%%m") do (
if "%%~aZ" GEQ "d" (
set "size=0"
set "status=Locked"
for /F "tokens=3,5" %%b in ('dir /A /-C /S /W "%%~fm\*" 2^>nul ^| %SystemRoot%\System32\findstr.exe /B /C:" "') do if "%%~c"=="" set "status=Unlocked" & set "size=%%~b"
set "data=0"
if !size! NEQ 0 set "data=Data"
if !size! == 0 if !status! == Unlocked set /A emptyFolderCount+=1
if !size! == 0 if !status! == Locked set /A deniedFolderCount+=1
if !size! GTR 0 set /A okFolderCount+=1
) else (
REM Else starts here
set "size=0"
set "status=Locked"
for /F "tokens=3,5" %%b in ('dir /A /-C /S /W "%%~fm" 2^>nul ^| %SystemRoot%\System32\findstr.exe /B /C:" "') do if "%%~c"=="" set "status=Unlocked" & set "size=%%~b"
set "data=0"
if !size! NEQ 0 set "data=Data"
if !size! == 0 if !status! == Unlocked set /A emptyFileCount+=1
if !size! == 0 if !status! == Locked set /A deniedFileCount+=1
if !size! GTR 0 set /A okFileCount+=1
)
)
)
echo !deniedFolderCount! !emptyFolderCount! !okFolderCount!
echo !deniedFileCount! !emptyFileCount! !okFileCount!
)
)
endlocal
pause
注意:由于File(s)
,此批处理文件仅适用于英文版Windows。