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.

5
  • What have you tried and what is not working with it? Can you post any of your example scripts? Commented Feb 26, 2013 at 14:26
  • for testing purposes Commented Feb 26, 2013 at 14:44
  • for /D /R c:\test %X IN (*.something) DO echo %X > test.txt. How do I match an exact folder name though? Commented Feb 26, 2013 at 14:45
  • and it doesn't go only one level deep Commented Feb 26, 2013 at 14:47
  • 1
    Can you use Powershell? And will you know the sub-folder names (e.g. Folder 2, Folder 3...) ahead of time? Or do you want to just delete everything under the first level folders if "folder 1" exists? Commented Feb 26, 2013 at 14:52

1 Answer 1

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 ) ) 
2
  • 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 Commented Feb 26, 2013 at 15:01
  • ah nevermind, I see where it goes into the folder now Commented Feb 26, 2013 at 15:01

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.