Kacimo Benziane
Kacimo Benziane

Reputation: 17

delete exe files smaller than a specific size

I would like to delete all exe files whose size is less than 400 kb in one folder, either with a batch file of VBScript.

I tried this one, but it is not working:

@echo off setlocal
for /f  "usebackq delims=;" %%A in (`dir /b *.exe`) do If %%~zA LSS 3145728 del "%%A"

Upvotes: 0

Views: 415

Answers (1)

Magoo
Magoo

Reputation: 79983

@echo off 
setlocal
for /f  "usebackq delims=;" %%A in (`dir /b *.exe`) do If %%~zA LSS 3145728 ECHO del "%%A"
for /f  "delims=" %%A in ('dir /b *.exe') do If %%~zA LSS 409600 ECHO del "%%A"

GOTO :EOF

Other than the setlocal should be on a separate line (which is irrelevant) there appears to be nothing wrong with your code in principle.

I've added an ECHO command before the del - just as a safety measure to not delete the file but simply show its name so that you don't delete files until you're ready.

The new line I've added simply does exactly the same thing, but more simply. And you say "400K" but 3145728 is not the 400K you mention.

You would have to run this file with the current directory=the directory from which you wish to make the deletion(s). If you're running it from a "shortcut", you'd need to add a new line

cd \where\to\delete\dir

before the for command.

Upvotes: 3

Related Questions