I'm trying to sort out a bunch of folders in Windows 7. I have a bunch of folders and some contain a file index.txt and some don't. What I want to do is move the folders that do have index.txt into a different directory so I separate the ones that do and do not contain a file called index.txt

How can I do this? I tried using the built-in Windows 7 search but it doesn't seem to do what I need.

Thanks!

link|improve this question
feedback

1 Answer

up vote 1 down vote accepted

From command line:

for /d %f in ("D:\A Bunch of Folders\*") do @if exist "%~f\index.txt" move "%~f" "EC:\With indexes"

This example will check all folders under D:\A Bunch of Folders and move the ones with indexes to E:\With indexes. Adjust to match your real paths, of course.

If you want the command to work recursively (that is, to also check subfolders, sub-sub-folders, and so on), add /r (for /r /d).

link|improve this answer
I always think your avatar looks like a sleeping tiger. – surfasb Dec 29 '11 at 13:00
Thanks worked great! Just wanted to point out that in your code you have the output folder as "EC:\With indexes" instead of "E:\With indexes" – Funkafied Jan 6 at 8:25
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.