Recursion with Folder Heirarchy Through Batch There were two issues that I was facing. So I would go step by Step. ISSUE 1: suppose that I have a text file with contents as:
1)a
2)b
3)c
4)d
Now in some folder C:\Output I have some files with extension say .1
I want to delete all other files from that folder Output apart from the files listen in the Text file.
That means I want a script that would leave only those files which are listed in that text file and delete all others. This issue got resolved with this script : @echo
cd c:\output
PAUSE
for /f %%a in (C:\Files.txt) do attrib +h %%a
PAUSE
del /q c:\output\*.* /A-h
for /f %%a in (c:\Files.txt) do attrib -h %%a ISSUE 2: Now what I want is that suppose in that folder output I have hierarchy of folders with names as
a, b , c, d, e....and so on.
Some of these folders might be empty whereas some of these might have some files or maybe another subfolder in it.
I want to write a script so that my above script checks into all the folders and if it finds that folder empty then it comes out and looks into next folder.
So in all all the folders get analysed and the files whose names were not there in the text file get deleted, whether those files belong to the subfolders or to the root folder. My script should analyze every folder.
I hope I am able to make you people understand what I am trying to do.
Please help.
Thanking you
scream |