Jump to content

Photo

Removing files under a specific size with Batch


  • Please log in to reply
3 replies to this topic

#1 SpleenBeGone

SpleenBeGone

    Deer Leader of the Goriest Revolution

  • Administrators
  • 14,951 posts
  • LocationHouston

Posted 19 July 2014 - 08:03 AM

So I recently recovered an entire hard drive which left me with a metric fuck ton of tiny files. It takes roughly 30 minutes for the folder to even open which means conventional deleting methods are out the window. After a bit of research I came up with a simple batch script that can be configured to delete files under a specific size. Here it is set to delete anything from the specified folder under 5Kb.

 

:: BATCH SCRIPT START
@ECHO OFF

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

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

:: Set following variable with path to check insided for files
SET Folder=G:\Billy

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

 


nmjUGDL.jpg

#2 Calvary

Calvary

    Conceptual

  • Members
  • 6,624 posts
  • Locationwww.

Posted 19 July 2014 - 12:25 PM

That's beautiful. >w>

 

I used to know how to write some pretty complex batch but I forgot everything. :(


tumblr_om7nwjm5Wm1rsea1wo1_500.gif
Ask for my discord/Insta/Tumblr if you want.


#3 Champion of Cyrodiil

Champion of Cyrodiil

    Gigabyte

  • Members
  • 776 posts
  • LocationVirginia

Posted 04 August 2014 - 07:17 AM

And why not throw in some bash for good measure...

 

$ find -type f -size -5k -delete

 

also, greater than 5k:

 

$ find -type f -size +5k -delete

 

http://linux.about.c...lcmdl1_find.htm



#4 DeadChannel

DeadChannel

    Gigabyte

  • Members
  • 1,088 posts
  • LocationNotlob

Posted 04 August 2014 - 02:53 PM

ooh, that's useful.


I'm fearful, I'm fearful, I'm fearful of flying, and flying is fearful of me.