標籤:尋找指定大小檔案
@echo off
setlocal enabledelayedexpansion
if "%1" equ "/?" (
goto helpinfo
)
:///ensure the command have the "Dir" parameter
if "%1" equ "" (
goto helpinfo
)
:///if first parameter is /c,collect info of the directories
if "%1" equ "/c" (
set /a dirnum=0
set /a filenum=0
set /a filesize0=0
set /a filesize1=0
for /r %2 %%a in (.) do (
set /a dirnum=!dirnum! + 1
)
for /r %2 %%a in (*) do (
set /a filenum=!filenum! + 1
set /a filesize0=!filesize0! + %%~za
if !filesize0! gtr 99999999 (
set /a filesize1=filesize1 + filesize0 / 1024
set /a filesize0=0
)
)
set /a filesize1=filesize1 + filesize0 / 1024
echo all directories number %2: !dirnum!
echo all files number %2: !filenum!
echo all files size %2: !filesize1!K
exit /b 0
)
:///////////if first parameter is not "/c",find files
if not exist %1 (
echo 目錄不存在
exit /b 1
)
:///ensure the parameter [SIZE_VALUE] is numerial number
if "%2" neq "" (
set /a temp = 1
set /a b = !temp! + %2
if !b! equ 1 (
echo 檔案大小值為非數實值型別
exit /b 1
) else (
set /a standardSize = %2 * 1024
)
)
://////collect current dir information
if "%2" equ "" (
call :findFileGreaterThan %1 1048576
) else (
call :findFileGreaterThan %1 %standardSize%
)
goto :eof
:findFileGreaterThan
:///get all file and file size ,output to %temp%\fileAndSize
set /a size = %2
for /r %1 %%a in (*) do (
if %%~za gtr %size% echo %%~za %%a
)
goto :eof
:helpinfo
echo.
echo 擷取指定目錄下大於給定值的所有檔案
echo.
echo %0 dir [SIZE_VALUE]
echo %0 /c [dir] 收集指定檔案夾下[不指定dir,預設目前的目錄]的資訊,包括:所有目錄數,所有檔案數
echo dir 要搜尋的目錄,如果目錄為磁碟機,必須指定為此格式:c:\或者d:\
ECHO SIZE_VALUE 檔案大小臨界值,單位為k,其中1k = 1024byte,不指定預設尋找大於1M的檔案
echo.
exit /b 0
本文出自 “記不起從前杯酒” 部落格,請務必保留此出處http://9429042.blog.51cto.com/9419042/1793772
windows7系統上尋找大於指定大小的檔案