Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete files less than a specific size

I would like to delete all files that are less than a specific size in a directory. Does anyone know if there is a Windows command that will do this? something like del *.* where size<3kb

I am currently doing this:

for /F %%A in ("*.pdf") do If %%~zA LSS 20103409 del %%~fA

and the ouput I get is:

C:\Documents and Settings\agordon\Desktop\test>If 6440450 LSS 20103409 del C:\Do
cuments and Settings\agordon\Desktop\test\US Tox 01-06-11.pdf
The system cannot find the path specified.

...even though that PDF file is small enough to be deleted.

What am I doing wrong?

This is actually working:

FOR %%F IN (*.pdf) DO (
IF %%~zF LSS 20103409  DEL %%F
)

However it is not recognizing the file names because they have spaces! How do I convert the Windows name to a "DOS" name in that script? For example, the Windows name is file name.pdf I would probably need to convert to "DOS" and it would look like this file_name.pdf or something like that.

like image 521
Alex Gordon Avatar asked Oct 16 '25 04:10

Alex Gordon


1 Answers

Try this from a batch script:

@echo off
setlocal
for /f  "usebackq delims=;" %%A in (`dir /b *.pdf`) do If %%~zA LSS 3145728 del "%%A"
like image 105
Mrchief Avatar answered Oct 18 '25 22:10

Mrchief