Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

Windows 7: DOS Batch - Forfiles - deleting specific file extensions

19 Sep 2011   #1

Win 7 32-bit
DOS Batch - Forfiles - deleting specific file extensions

Hey all. I've reviewed several different examples of how forfiles works. To set the stage, I need to automatically remove files with a file extension of .0 followed by numbers that increment and these files would be 7 days or older. Unfortunately, none of the examples or forfiles /? usage explains how to specify what I need done to file extensions that end with .0xxxxx

Here is what I have so far:

echo on 
rem Remove stats-bin.0* files older than 7 days 
forfiles /p "c:\Program Files\MySQL\MySQL Server 4.1\data" /m stats-bin.0* /c "cmd /c del /Q @file  /d -7 
rem pause
Within the data directory, there are stats-bin.index files, stats.0XXXXX files and others. The goal here is to only remove those files that begin with stats-bin.<numbers>

Currently, this script isn't doing anything. Trying to troubleshoot what I'm doing wrong here. If anyone has another forum they frequent for Windows script-specific help, I'd appreciate it (if this isn't the preferred place to post such a thing).

My System SpecsSystem Spec
27 Sep 2011   #2

Windows 8.1 ; Windows 7 x86 (Dec2008-Jan2013)

You forgot closing quotes for cmd part.
forfiles /p "c:\Program Files\MySQL\MySQL Server 4.1\data" /m stats-bin.0* /c  "cmd /c del /Q @file" /d -7 
Have just tested that. Works like a charm!
My System SpecsSystem Spec

 DOS Batch - Forfiles - deleting specific file extensions

Thread Tools

Similar help and support threads
Thread Forum
Batch file to Sort and Move specific files by identifying word inside
Hi All... I will explain what I need in as much detail as possible. I need a batch file to move specific files into a separate folder,possibly by opening my hex editor,searching for the word "body" ( without the quotes ) and if found ,close hex editor,move file to a folder called "moved" ,then go...
General Discussion
Hide extensions for known file types - only in specific folders
Is that possible? Alternatively, can I hide the extension of specific files (NOT all files with the same extension)? Thank you.
Batch File that grabs file names from folder to insert into batch file
Ok I'm totally at a loss on how to word this so I'm just going to write it out the best that I can... :confused: First I have a batch file that I'm writing that will convert mp4 files to mp3 files (I have a lot) for a buddies band using ffmpeg. Here's the code that I'm using: ffmpeg -i...
General Discussion
Deleting registry keys with a batch file?
I downloaded a beta version of a program and it for some reason it has a "usage count" in the registry which denies access to the program after 10 uses. When i delete the key it works again but it's pretty annoying to keep deleting it through the registry all the time. I want to make a batch...
General Discussion
Help with Batch file, if statement in a specific time.
hi, I am working on a batch file, such as If this is not possible, then just simply, Thanks!
General Discussion

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 09:55.
Twitter Facebook Google+ Seven Forums iOS App Seven Forums Android App