Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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!

share|improve this question
add comment

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).

share|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 '12 at 8:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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