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
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Feb 10, 2010 at 02:10 PM
Related:
- Delete subfolders except specified folders?
- Delete my whatsapp account without app - Guide
- How to delete whatsapp account without phone - Guide
- How to delete snapchat account - Guide
- How to delete icloud tabs - Guide
- How to delete blacklist number - Guide
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
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.
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Feb 10, 2010 at 02:10 PM
Feb 10, 2010 at 02:10 PM
Could it be that attrib of folder or files in them is +R
Feb 10, 2010 at 01:10 PM
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?