How to delete N files of X type from Y subfolders from a Windows batch file?


How to delete N files of X type from Y subfolders from a Windows batch file?



I'm trying to write a windows batch file that can delete files from subdirectories. I would rather not hard code the directory structure in, so I can use this process with other projects.

  • I need to delete files of X type,
  • I have the parent folder C:\MyProject,
  • There are Y subfolders C:\MyProject\?,
  • There are N files to delete.

Is there a quick del (of type) function I am simply missing?




How do you insert msi into custom Windows install?

1:



Dragging files to an .exe sets different working directory
Actually you can use the standard del command:.
Mac Style “Dvorak - Qwerty Command” keyboard mapping for Windows?
c: cd MyProject del /S *.type 
Where type is the extension you want to delete and the /S parameter will check in all subfolders of MyProject..
Create a process from a driver


How to disable the little touch-keyboard on Windows edit controls


How to get my company's proxy transparent?

2:



kernel mode driver write to file
If the del command didn't have the /S flag to delete recursively, I'd use AWK to do something like this (you'd need the UNIX tools for Windows):.
Connecting Windows Driver to Userland Service
dir MyProject\*.* /ad /s /b | gawk "{print \"del \\\"\" $0 \"\\*.type\\\"\";}" | cmd 
My 2 cents, in case you ever need to do something similar (applying a program to all files of X type in all subfolders) with a command that lacks a recursive flag..



94 out of 100 based on 44 user ratings 544 reviews