deleting subfolders except specified list

February 10, 2010 at 05:16:51
Specs: Windows XP

I am working with 3d animation and I need to clean up my project before archiving.

I am compositing the renders in Fusion and when I list the footage used I get a list like this:


Now, if I want to delete all folders in the OUTPUT directory EXCEPT for the folders listed, is there a way I can write a batch script that would do that for me?

I reckon I'd have to either edit the specified list (removing the actual file names) or tokenize the strings so the paths for exclusion are converted to paths without the last bit (the file names).

I have a bunch of "Sequences" with multiple shot-folders in them, so I really hope there's a more automated way of doing this than manually go through and delete the unused footage folders.

Thank you sooo much!

See More: deleting subfolders except specified list

Report •

February 10, 2010 at 05:24:54


Do you mean to exclude all folders in


Or do you mean :
all except :

Are there more exlusions, or are the above exactly the exclusion list. Reason for asking is that when the exclusion list becomes larger, it has an impact on coding. One exclusion is easy to make, 2 as well, becomes more difficult with 3, etc. etc.

Will the exclusion list grow, in means of time ?

Report •

February 10, 2010 at 06:37:45
I want to delete all folders in the OUTPUT directory EXCEPT V011\Fallof

This is the exact exclusion list, but in other sequence- or shot folders the list might look different, and yes, some lists of used footage (that I'd want to keep) might include up to 20 different folders. But the list of directories ((that I'd want to keep) would be provided every time.

I've tried:

::== deleteUnused.bat
@echo off
dir /s/b/ad "C:\batchTest" > allFolders.txt
find /v /i "C:\batchTest\keepThisOne" < allFolders.txt > others.txt
find /v /i "C:\batchTest\keepOneFolderInHere\OUTPUT\V011\diffuseIrradiance" < others.txt > others2.txt
for /f "tokens=*" %%U in (others2.txt) do (
echo rmdir /s /q %%U )

The problem with this one is that it seems to go through all folders and the txt files it spits out looks correct. But it doesn't actually remove anything, even using deltree /y.
And if it DID, I'd imagine it would go through the list and delete the first unused path in the list, and when the loop reaches a folder to keep it might be inside one that has allready been deleted.
Say, OTHERS2.txt would contain


and thus be deleted even though


is a folder I'd like to keep.

Report •

February 10, 2010 at 06:42:31
so, I'd have exclude parent folders that contains the used footage from the dir list of all folders as well.

Report •

Related Solutions

February 10, 2010 at 06:49:08
plus, the way I tried it, I would have to make 20 iterations of the text file if I had 20 folders I would like to exlude

dir....root> allFolders.txt
find...."exceptThisOne" <allFolders.txt> exlude01.txt
find...."andThisOne" <exlude01.txt> exlude02.txt
find...."andThisOne" <exlude02.txt> exlude03.txt
find...."andThisOne" <exlude03.txt> exlude04.txt
find...."andThisOne" <exlude04.txt> exlude05.txt

for...... (exlude05.txt) do(....)

And that can quickly become reeeeally messy and tedious.

Do you think a python script would be better suited?

Thank you veeeery much for the reply, btw

Report •

February 10, 2010 at 07:23:31
btw, tvc, yes I meant all except:

Report •

February 10, 2010 at 12:43:54
findstr with /g might do it the way you want (where i put "fusion.txt" as the name of the file created by fusion)

dir /ad \\externalDrive\projects\ThisProject\Sequence1\Shot05\OUTPUT > alldirs
findstr /v /g:fusion.txt alldirs>deldirs
for /f %%a in deldirs do echo deltree /y %%a

Report •

February 11, 2010 at 01:57:48
thank you for your reply.
Where do I put fusion.txt? In the same dir as the batch file?
When I tried your code alldirs and deldirs were identical..

Report •

February 11, 2010 at 08:14:06
" am compositing the renders in Fusion and when I list the footage used I get a list like this: "

my bad, i took this as meaning that Fusion generated a list into a file somewhere ("Fusion.txt").
Can the generator (Fusion) output the list of active footage to textfile? If so, that is the source of the file "fusion.txt".
It doesn't matter where you put the batchfile or the fusion.txt file, as long as the you can find the batchfile and the batchfile can find fusion.txt and the root directory "OUTPUT".
f/e, using just the simple root of c for both bat and listfile:

set mpath=c:\
dir /ad \\externalDrive\projects\ThisProject\Sequence1\Shot05\OUTPUT > mpath\alldirs
findstr /v /g:mpath\fusion.txt alldirs>mpath\deldirs
for /f %%a in mpath\deldirs do echo deltree /y %%a

I know it should work, its just a matter of ironing out the details.
i oversimplified things i think, i'm editing to try and correct my oversight:
mpath is any dirpath you want to use for working, it could be OUTPUT or some other.
set mpath=c:\work
here's a simplified sample of the structure:
(where E stands for \\ExternalDrive)
this is the output from your active footage list...
first it needs the filename stripped off:
for /f %%a in (fusion.txt) do >>mpath\work1.txt echo %%~dpa

work1 is then used as the key of which subdirs to retain vs which
to remove, and should look likt this:

dir /b /s /ad \\E\proj\Th\OUTPUT >> mpath\alldirs.txt

this gives a list of ALL the subdirs under OUTPUT, like:

now everything that's in work1 can be "inverse-matched" against
work1 to give list of ones to delete:
findstr /v /g:mpath\work1.txt alldirs>mpath\deldirs
and deldirs should look like:

for /f %%a in (deldirs) do echo deltree /y %%a
but note that subdirs off legit. dirs, and emptied main subdirectories, will stll be dangling (ie not deleted):

since deltree is not native to XP (at least it's not on my machine, i had to
port it from winME), another option is to use attrib tagging combined with the del /s,
but that gets more complicated and since you have deltree i won't go into
all that.

Report •

Ask Question