Move Folders Containing Certain File

2

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!

Funkafied

Posted 2011-12-29T06:35:06.803

Reputation: 23

Answers

1

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

user1686

Posted 2011-12-29T06:35:06.803

Reputation: 283 655

I always think your avatar looks like a sleeping tiger. – surfasb – 2011-12-29T13:00:36.020

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 – 2012-01-06T08:25:46.750