Jump to content

Recursively search for 100kB files and delete them


Retro-Starr

Recommended Posts

I have a script were I need to make it recursively search for 100kB and delete them. The problem is that once files are in a folder, the script doesn't care for the size and deletes everything in the folders.

:: @echo off
:: schtasks /create /sc hourly /tn "Search and Destroy" /tr "goto :task"

:task
for /r %%g in (*.wav) do [
goto :check
]

:check
:: 102400 is in bytes and equates to 100kB
if %~z1 leq 102400 (
:: del /q /f %1
del /q /f %%g
goto :next_arguement
) else (
goto :end
)

:next_arguement
shift
goto :check

:end
pause > nul
exit /b

This code should be structurally correct, but the "del /q /f %%g" doesn't delete anything unless it's "del /q /f %1" which is the command that loves to delete everything! The search for the wav files doesn't work either. I've been working on this for the past couple of days and am lucky I got this far! I would really appreciate any help on this.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...