标签:查找指定大小文件
@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
标签:查找指定大小文件
原文地址:http://9429042.blog.51cto.com/9419042/1793772