windows batch delete script

Posted on 2011-10-21
Last Modified: 2012-05-12
Hello all.  I need script similar to the one below which searches for files beginning with z and deletes them if less than a certain file size but...

unlike the script below, I have a known directory and I do not want to search the whole hard drive to save time.  

so the the script should delete all files that start with z, and LSS 7043000 , from this known path
c:\program files\main\qagame\

 set folder=
for %%D in (C D E F G H I J K) do (
  for /F "tokens=*" %%P in ('if exist %%D: dir /a:-d /s/b %%D:\~* ^| findstr /L /i \qagame\') do (
      if %%~zP LSS 7043000 del /s /q "%%~P"
Question by:icecom4
    LVL 5

    Accepted Solution

    This should do the trick:

    @echo off

    cd /D "c:\program files\main\qagame\"

    for /F "tokens=* delims=" %%i in ('dir z*.* /b /s') do IF %%~zi LSS 7043000 del /q /f "%%i"

    Author Comment

    hey this works thanks.  Just curious...would     ~*.zip  mean only zip files that start with ~ ?  Because I will want to make that small change.  
    LVL 5

    Expert Comment


    Author Closing Comment

    worked like a charm!

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Step by step guide to Clean and Sort your windows registry! Introduction: Always remember: A Clean registry = Better performance = Save your invaluable time In this article we're going to clear our registry manually! Yes, manually! The e…
    Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video discusses moving either the default database or any database to a new volume.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now