Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

scripting - Batch script to find files greater than 10MB in D drive in windows xp

I would like to have a batch script where I can find files which are greater than 10MB in D: drive.

Regards, Orbit.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here is a batch script that will list all files that are greater than a given size (in bytes) in a given directory and all its subdirectories:

@echo off

setlocal enabledelayedexpansion

set "SEARCH_DIR=%~1"
set "FILE_SIZE=%~2"

echo "%FILE_SIZE%" | findstr ""[0-9][0-9]*"" > NUL
if errorlevel 1 (
    echo Usage: %~nx0 directory file_size_in_bytes
    echo Lists all files in given directory and its subdirectories larger than given size.
    exit /b 1
)

if not exist "%SEARCH_DIR%" (
    echo "%SEARCH_DIR%" does not exist.
    exit /b 1
)

for /R "%SEARCH_DIR%" %%F in (*) do (
    if exist "%%F" if %%~zF GEQ %FILE_SIZE% echo %%F
)

The script first performs some error checks and than recursively iterates through all the files in the given dir, printing the paths of those files whose size is greater or equal to the given size.

For example, to list all files greater than 10MB in D: drive, invoke the script in the following way from the command prompt:

C:>list_larger_than.bat D: 10000000

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...