Recursive deleting of file types - Windows 7

The friendliest place on the web for anyone with an RV or an interest in RVing!
If you have answers, please help by responding to the unanswered posts.

Tom

Administrator
Joined
Jan 13, 2005
Posts
51,854
I need to delete a bunch of files of a given type from numerous nested folders/subfolders on a Win 7 machine. Manually deleting them is proving to be a daunting task. A google search returns very few answers, including this one from a command line:

del /s *.xyz  (xyz = file type/extension).

Anyone used this successfully (i.e. without deleting other file types)? Is it possible to limit this to one folder (and its subfolders) instead of an entire drive?

Any suggested alternatives? A GUI version would be nice - so I can see what I'm about to delete.

TIA.
 
That should work fine.  The /s says to delete in the current directory and all subfolders.  Just make sure you are in the correct folder when you give the command.

Or you can use Windows Explorer to navigate to the root folder, then sort by extension, and select the files to delete.  But that won't operate on the subfolders, you'd have to do each one individually.  The command line is easier and faster.
 
Thanks Ned. It appears to run, but doesn't delete any files even if run from the subfolder. Just realized that the files I need to delete have names like this:

.filename.abc.xyz  (note the "." at the beginning of the filename).

These are all small files created by a prior backup utility that no longer works; The file names include the file name and extension of the original (backed up) file. In the above example, the original (backed up) file names looks like this:

filename.abc (without the leading period and without the trailing .xyz)

I need to retain these original files.

 
From Windows Explorer select the folder containing the files - then execute a search (upper right corner) for the files you want to delete. You only need to enter enough significant characters for the find. After the search highlight all the files found -- and delete them.
 
The leading . shouldn't be a problem.  I just created such a file and was able to delete it from the command line.  Before running the del command, run a dir command with the same parameters and see exactly what files will be deleted.

Bob's method is another possibility, but slower.  You may have to tweak the search parameters to get what you want.
 
Thanks Bob. It didn' t occur to me to search while in windows Explorer.

It appears to have found all the files (41,000 of them), and it's still running through the process. One nice thing about using WE is that you can see and select what's about to be deleted. The downside is that, unlike deleting via the command line, the files are moved to the recycle bin, and need to be deleted from there. Presumably thls will be a simple 'empty recycle bin' step. Meanwhile, Windows is telling me the PC is low on memory, and I should close WE; I'm going to let it run and see what happens.
 
Thanks Ned, I'll try that on the next directory I copy over from the backup (when the other process has finished).
 
You can hold the shift key while you press delete to bypass the recycle bin if you are brave enough!

Jeff
 
Depending on the size of the files, 41,000 files may fill the Recycle Bin and if so, the rest of the files will be permanently deleted anyway.  I almost always use Shift-Del when deleting large files so as not to fill up the recycle bin.
 
They're all <1K, typically half of that.

The process seemed to hang with <10 files remaining. Had to force a restart, and I'm waiting to see the result  ???
 
Tom said:
Thanks Bob. It didn' t occur to me to search while in windows Explorer.

It appears to have found all the files (41,000 of them), and it's still running through the process. One nice thing about using WE is that you can see and select what's about to be deleted. The downside is that, unlike deleting via the command line, the files are moved to the recycle bin, and need to be deleted from there. Presumably thls will be a simple 'empty recycle bin' step. Meanwhile, Windows is telling me the PC is low on memory, and I should close WE; I'm going to let it run and see what happens.

If still running after finding all the files, it is doing a sequential vs. indexed search.

As to the downside, some would argue whether placing in the recycle bin is good vs. bad. I have been saved by the recycle bin a number of times when deleting an entire folder, for example. A click on empty works for me.  I find a command line DEL fairly dangerous - and have for about 30 years. WE is slower coupled with the recycle bin, but safer for an older guy like me.  :)
 
No disagreement on the safety issue Bob; The unknown/ blind aspect of a command line delete is what caused me to start this topic. OTOH I have copy of everything on the backup drive.

If still running after finding all the files, it is doing a sequential vs. indexed search.

I believe the search was complete, and what was still running was the deletion of all 41K files I'd highlighted.


 
The unknown/ blind aspect of a command line delete is what caused me to start this topic.
That's why you do a DIR with the same parameters first :)  You can scroll the command window to see exactly what files will be affected.
 
Update: Interrupting the 'hung' delete with <10 files remaining resulted in the entire directory (wanted and unwanted files) disappearing. Prior to starting this delete process, I'd spent several hours 'manually' consolidating and deleting numerous subfolders and files. Time to start over  :(  
 
Stop the presses! I forgot that yesterday I'd played musical chairs with drives - moved drive letters around and changed assignment of primary and backup drives  :-[  Moving forward  ;D
 
C:\del /?
Deletes one or more files.

DEL [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
ERASE [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names

  names        Specifies a list of one or more files or directories.
                Wildcards may be used to delete multiple files. If a
                directory is specified, all files within the directory
                will be deleted.

  /P            Prompts for confirmation before deleting each file.
  /F            Force deleting of read-only files.
  /S            Delete specified files from all subdirectories.
  /Q            Quiet mode, do not ask if ok to delete on global wildcard
  /A            Selects files to delete based on attributes
  attributes    R  Read-only files            S  System files
                H  Hidden files              A  Files ready for archiving
                I  Not content indexed Files  L  Reparse Points
                -  Prefix meaning not

If Command Extensions are enabled DEL and ERASE change as follows:

The display semantics of the /S switch are reversed in that it shows
you only the files that are deleted, not the ones it could not find.

C:\>

Your /S switch should work fine as long as your extensions are consistent. 
 
Thanks Ed. Way too many options there for my "simple" task.
 
Closure - I finally got this job done; I used Bob's method and took smaller bites, avoiding running out of memory. It took a while, in between other things in life over the last few days, but it felt a little "safer" being able to see what was about to be deleted. Meanwhile, I learned something new; I hadn't previously noticed that search box in the top right when using W.E.
 
Windows search does work, but can be very slow.  It also can slow down the computer when it's indexing in the background.  I use a search engine called Everything that has no discernible effect on the computer operations and indexes every file on those drives I specify.  I've shut off the Windows search service and just use Everything.  It's almost instantaneous in showing results.
 

Members online

Forum statistics

Threads
131,749
Posts
1,384,209
Members
137,520
Latest member
jeep3501
Back
Top Bottom