我想计算一个文件大小大于零的目录中有多少* .diff文件。
如果有多个文件,我需要更改ERRORLEVEL。
为了这样做,批处理命令是什么?
答案 0 :(得分:0)
要列出PowerShell下的所有非空* .diff文件,您可以使用以下脚本:
"`n"
$filePath = Read-Host "Please Enter File Path to Search"
"`n"
Get-ChildItem -Recurse -Force $filePath -ErrorAction SilentlyContinue | Where-Object { ($_.PSIsContainer -eq $false) -and ( $_.Name -like "*.pdf") -and ( $_.Length -gt 0kb) } | Select-Object Name,Directory| Format-Table -AutoSize *
write-Host "------------END of Result--------------------" -ForegroundColor Magenta
答案 1 :(得分:0)
@ECHO OFF
SETLOCAL
SETLOCAL ENABLEDELAYEDEXPANSION
SET "sourcedir=U:\sourcedir"
:: kill any .diff files
DEL %sourcedir%\*.diff >NUL 2>NUL
:: call the detect routine
CALL :detect
ECHO run 1: %countfg0% non-zero .diff files found; errorlevel=%ERRORLEVEL%
:: 1 zero-length file
COPY NUL "%sourcedir%\1.diff" >NUL 2>NUL
CALL :detect
ECHO run 2: %countfg0% non-zero .diff files found; errorlevel=%ERRORLEVEL%
:: 2 zero-length file
COPY NUL "%sourcedir%\2.diff" >NUL 2>NUL
CALL :detect
ECHO run 3: %countfg0% non-zero .diff files found; errorlevel=%ERRORLEVEL%
:: 2 zero-length file + 1 non-zlf
ECHO.>"%sourcedir%\3.diff"
CALL :detect
ECHO run 4: %countfg0% non-zero .diff files found; errorlevel=%ERRORLEVEL%
:: 2 zero-length file + 2 non-zlf
ECHO.>"%sourcedir%\4.diff"
CALL :detect
ECHO run 5: %countfg0% non-zero .diff files found; errorlevel=%ERRORLEVEL%
:: 2 zero-length file + 3 non-zlf
ECHO.>"%sourcedir%\5.diff"
CALL :detect
ECHO run 6: %countfg0% non-zero .diff files found; errorlevel=%ERRORLEVEL%
:: 0 zero-length file + 3 non-zlf
DEL %sourcedir%\1.diff >NUL 2>NUL
DEL %sourcedir%\2.diff >NUL 2>NUL
CALL :detect
ECHO run 7: %countfg0% non-zero .diff files found; errorlevel=%ERRORLEVEL%
:: 0 zero-length file + 2 non-zlf
DEL %sourcedir%\4.diff >NUL 2>NUL
CALL :detect
ECHO run 8: %countfg0% non-zero .diff files found; errorlevel=%ERRORLEVEL%
:: 0 zero-length file + 1 non-zlf
DEL %sourcedir%\3.diff >NUL 2>NUL
CALL :detect
ECHO run 9: %countfg0% non-zero .diff files found; errorlevel=%ERRORLEVEL%
GOTO :EOF
:detect
:: set count-of-(files greater than 0)
SET /a countfg0=0
FOR %%a IN ("%sourcedir%\*.diff") DO IF %%~za neq 0 SET /a countfg0+=1
IF %countfg0%==0 EXIT /b 0
IF %countfg0%==1 EXIT /b 1
EXIT /b 2
这是一个测试/检测例程,在测试目录中创建0长度和非零长度的.diff
文件。您需要更改sourcedir
的设置以适合您的具体情况。
:detect
例程实际上完成了工作,需要使用当前结构called
。其余的只是为er测试建立不同的测试条件。