Sunday, March 1, 2009

Batch script to delete files greater than a certain size

Copy and paste following batch script into notepad and save it with any file name having .cmd extension then execute script from command line.

:: BATCH SCRIPT START
@ECHO OFF

:: Set following variable for file size in Bytes (1024 Bytes=1KB, 1024KB=1MB, 1024MB=1GB)
SET /A FileSize=1048576

:: Set following variable for file extensions to check (*.* = all files)
SET Filter=*.*

:: Set following variable with path to check insided for files
SET Folder=C:\MyFolder

FOR /R "%Folder%" %%F IN (%Filter%) DO (
IF %%~zF GTR %FileSize% (
ECHO Deleting "%%F"
DEL /F "%%F"))
EXIT /B /0
:: BATCH SCRIPT END

4 comments:

  1. This was a great help! Worked wonderfully!

    ReplyDelete
  2. Thank you, this script is just what I needed!

    ReplyDelete
  3. Thanks a lot Farhan...keep up the good work...!

    ReplyDelete