Delete subfolders except specified folders?

Closed
avondrei - Feb 10, 2010 at 06:09 AM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Feb 10, 2010 at 02:10 PM
Hello,

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:

\\externalDrive\projects\ThisProject\Sequence1\Shot05\OUTPUT\V011\Falloff\Falloff_0000.exr
\\externalDrive\projects\ThisProject\Sequence1\Shot05\OUTPUT\V012\Mask\Mask_0000.exr
\\externalDrive\projects\ThisProject\Sequence1\Shot05\OUTPUT\V012\Houses\Houses_0000.exr
\\externalDrive\projects\ThisProject\Sequence1\Shot05\OUTPUT\V014\background\background_0000.exr

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!

2 responses

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Feb 10, 2010 at 08:26 AM
if there are only few folders to be kept, have you considered option of copying folders to temp location and then remove all folders and then bring back the copied one.
0
yes I have considered it, but seeing that these folders are on an external drive on the network and contains in total up to maybe a couple of terrabytes of data, I'm afraid the just the copying will take months....

Using my example from my first post I want to delete all folders in the OUTPUT directory EXCEPT
V011\Fallof
V012\Mask
V012\Houses
V014\background

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, or 40, different folders. But the list of directories ((that I'd want to keep) would be provided every time in the form of aforementioned list.

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 )
:: DONE
pause

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

C:\batchTest\keep_one_folder_in_here\OUTPUT

and thus be deleted even though

C:\batchTest\keepOneFolderInHere\OUTPUT\V011\diffuseIrradiance

is a folder I'd like to keep. So, I'd have exclude parent folders that contains the used footage from the dir list of all folders as well.

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?
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Feb 10, 2010 at 02:10 PM
Could it be that attrib of folder or files in them is +R
0