Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
818 views
in Technique[技术] by (71.8m points)

windows - 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 SettingsagordonDesktopest>If 6440450 LSS 20103409 del C:Do
cuments and SettingsagordonDesktopestUS 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...