0

Assume a file system with the following format

Folder A
--->Folder 1
--->Folder 2
--->Folder 3 etc..
Folder B
--->Folder 4
--->Folder 2
--->Folder 3
Folder C
--->Folder 1
--->Folder 2
--->Folder 3
--->Folder 4

I need to go one level deep, and only one level deep, and search for 'Folder 1'. If Folder 1 is there, then remove Folder 2 and Folder 3.

I can use a Windows batch file or some other programing language.

1 Answers1

0

The following script (or line) will check all directories within the current directory one level deep for the presence of Folder1\NUL, a well-known ugly trick to distinguish files from directories. Be careful around directories that contain spaces; they may be parsed as two separate locations for rmdir to do its damage.

for /D %%i in (*) do (
    if exist .\%%i\Folder1\NUL (
        rmdir /S .\%%i\Folder2
        rmdir /S .\%%i\Folder3
    )
)
Khaled
  • 36,533
  • 8
  • 72
  • 99
  • looks like does every folder in the current directory but not into the folders in that directory? For example in my post above, I need to go into Folder A, B and C and find the folder – user1983916 Feb 26 '13 at 15:01
  • ah nevermind, I see where it goes into the folder now – user1983916 Feb 26 '13 at 15:01