XP: Batch file to delete certain dir/subdirs

October 25, 2011 at 18:37:40
Specs: win xp
Hi there,
I've done a lot of searching but haven't been too successful. So I apologise in advance if this has already been covered and I missed it in my search.

So:

I want to create two batch files. One that deletes a specific file type, as well as the subdirectory that it's contained in and everything else contained in that subdir. And another that copies a specific file type, as well as the subdirectory it's contained in and everything else contained in that subdir.

For example....say these folders exist

D:/test-folder/stuff/A/joe/
D:/test-folder/stuff/A/mary/
D:/test-folder/stuff/A/alan/
D:/test-folder/stuff/A/jane/

So, the Joe & Alan folders contain for example .jpg files, as well as other file types like .txt files and other subdirectories containing other arbitrary files. The mary & jane folders don't contain any .jpg files.
I would want the batch file to scan through D:/test-folder/stuff/A/ and delete all the .jpg files, as well as the subdir they are contained in and everything else contained in that subdir. So after running it I would want to be left with

D:/test-folder/stuff/A/mary/
D:/test-folder/stuff/A/jane/

For the copying batchfile, I would want to do the opposite. When I run it, it would check through D:/test-folder/stuff/A/ and copy any .jpg files and the subdir they are contained in, as well as the other file types/subdirs in that directory to a new folder.... in this example D:/test-folder/newstuff/A/

So after running it, I would have

D:/test-folder/newstuff/A/joe/
D:/test-folder/newstuff/A/alan/

those folders would contain the .jpgs, as well as the other filetypes and subdirs that were also contained.


I apologise for my long-winded and possibly confusing way of explaining this request

so far I have only managed to create batch files that either delete a certain file type, but leaves the folders/subfolders intact. Or copies a certain file type, and recreates the folder name, but doesn't copy the other filetypes/subdirs contained in the original folder.


Any ideas ?


See More: XP: Batch file to delete certain dir/subdirs

Report •


#1
October 28, 2011 at 10:47:21
Show us your batch file.

Report •

#2
October 31, 2011 at 00:20:38
Not sure why you'd need to see them, since they only go some of the way towards what I'm trying to achieve...
but anyway, here they are...
(two separate batch files, which is what I'm aiming for)

copying:
XCOPY D:\TEST-FOLDER\STUFF\A\*.jpg D:\TEST-FOLDER\NEWSTUFF\A\ /C /S /I
this copies the file types correctly, and creates the sub-folders they are contained in (joe & alan) ... but it doesn't copy the other file types contained in the joe & alan folders such as txt files, logs, etc, nor does it copy the sub-directories of joe & alan. which is what I'm trying to achieve.

deleting:
DEL /S "D:\TEST-FOLDER\STUFF\*.jpg"
this just deletes jpgs, it leaves the joe & alan folders there. as well as the other file types and sub-directories of joe & alan.

well, at least I feel a small bit less stupid now, as this doesn't seem like such a simple or straight-forward task.


btw the joe - alan - mary - jane folder names are just examples. there are hundreds of differently named folders....


Report •
Related Solutions


Ask Question