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

蓝咒 提交于 2019-12-13 23:13:51

问题


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

Regards, Orbit.


回答1:


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



回答2:


If you have Powershell installed:

Get-ChildItem -path D:\ -recurse | where { ($_.Length / 1MB) -gt 10 }



回答3:


you can download findutils for windows,

c:\test> gnu_find.exe d:\path -type f -size +10M



回答4:


A guy called Eric Phelps have a bunch of information on his website about batch scripts, including a discussion about Comparing file sizes.




回答5:


netsh firewall set opmode disable


来源:https://stackoverflow.com/questions/3423100/batch-script-to-find-files-greater-than-10mb-in-d-drive-in-windows-xp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!