# Moving files from 400 directories into one directory

**URL:** https://boards.straightdope.com/t/moving-files-from-400-directories-into-one-directory/579799
**Category:** Factual Questions
**Created:** [April 26, 2011, 6:39pm UTC](https://boards.straightdope.com/t/moving-files-from-400-directories-into-one-directory/579799 "2011-04-26T18:39:56Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![Mangetout](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/mangetout/32/19_2.png) [@Mangetout](https://boards.straightdope.com/u/Mangetout)
#### Post date: [April 26, 2011, 6:39pm UTC](https://boards.straightdope.com/t/moving-files-from-400-directories-into-one-directory/579799/1 "2011-04-26T18:39:56Z")

</div>

The hard drive crashed in my general-purpose home desktop PC the other day. Nothing would restore it to proper readability (I tried quite a few tools), but a utility called Photorec worked on the drive for 27 hours and recovered a great many files (hundreds of thousands of them\*) and placed them in a collection of some 500 separate directories on the destination volume.

So now I need to sift through the ashes and see what’s worth keeping, but it’s spread across hundreds of folders (photorec does this so you can start scrutinising the results while the recovery is ongoing, I think)

I’ve deleted a whole load of files I know I’m not interested in, from the Windows command line (by navigating to the folder containing the recovered subfolders and doing Del \*.dll /s), but now I want to move all files of a given type into folders of their own, so I can browse all examples of one type of file together.  
If I do XCopy with the /s switch, it will find them all, but it will just replicate the subfolder structure at the destination. I want to flatten the structure by one branch.

I tried searching for files of a specified type using the Windows search tool, but the hits were too numerous to be manageable - there are many thousands of files of some types.

So how can I do this? I have Windows XP and Ubuntu Linux 10.10 at my disposal.  
\*Some of them are icons, sounds, etc that must have been embedded in executables or dlls, etc, but the recovery process has reconstructed them as distinct files.

---

<div class="post-metadata">

### Author: ![Athena](https://avatars.discourse-cdn.com/v4/letter/a/35a633/32.png) [@Athena](https://boards.straightdope.com/u/Athena)
#### Post date: [April 26, 2011, 6:57pm UTC](https://boards.straightdope.com/t/moving-files-from-400-directories-into-one-directory/579799/2 "2011-04-26T18:57:19Z")

</div>

Boy, I just dug something out of the depths of my brain that I thought was gone forever. Behold the “FOR” loop:

for /R c:\dir1 %f in (_._) do copy %f c:\dir2

To move files of just a single type, like \*.mp3 files:

for /R c:\dir1 %f in (\*.mp3) do copy %f c:\myMP3Dir

---

<div class="post-metadata">

### Author: ![Mangetout](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/mangetout/32/19_2.png) [@Mangetout](https://boards.straightdope.com/u/Mangetout)
#### Post date: [April 26, 2011, 7:17pm UTC](https://boards.straightdope.com/t/moving-files-from-400-directories-into-one-directory/579799/3 "2011-04-26T19:17:29Z")

</div>

Brilliant - that does exactly what I needed. Thanks!

---

<div class="post-metadata">

### Author: ![Reply](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/reply/32/15952_2.png) [@Reply](https://boards.straightdope.com/u/Reply)
#### Post date: [April 26, 2011, 7:23pm UTC](https://boards.straightdope.com/t/moving-files-from-400-directories-into-one-directory/579799/4 "2011-04-26T19:23:07Z")

</div>

Just so you know, you can also do this with Windows Explorer (the GUI) by doing a search in the parent folder and looking for files of type whatever. The results will be unfolderized and you can just drag the whole list of them into another folder.

---

<div class="post-metadata">

### Author: ![dzero](https://avatars.discourse-cdn.com/v4/letter/d/5f9b8f/32.png) [@dzero](https://boards.straightdope.com/u/dzero)
#### Post date: [April 26, 2011, 7:29pm UTC](https://boards.straightdope.com/t/moving-files-from-400-directories-into-one-directory/579799/5 "2011-04-26T19:29:29Z")

</div>

> [@Reply](#):
>
> Just so you know, you can also do this with Windows Explorer (the GUI) by doing a search in the parent folder and looking for files of type whatever. The results will be unfolderized and you can just drag the whole list of them into another folder.

Yes. To flesh that out a little, view windows explorer in split pane mode with directories on the left and files on the right. In the search box (upper right) put in _._ and hit enter.

Go make a cup of tea, relax, have a cookie.

When you come back, all the files will be listed together.

sort by name.

select the first file, then press cntl-shft-end and all files will be highlighted.

right click and say cut (or copy).

select the target directory in the left pane, right click and say “paste”. All the files will be in that directory now

Even though you don’t actually move the files (just the reference in the file allocation tables) it will still take a while.

If you do move files between drives, get teracopy (free) - much faster than windows copy - [Products - Code Sector](http://www.codesector.com/teracopy.php)

You may also want to get fast duplicate file finder (free), but be warned that searching and matching a few hundred thousand files will take overnight - at least. It goes faster if you break it into sub directories and do the job piecemeal.

---

<div class="post-metadata">

### Author: ![Quartz](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/quartz/32/267_2.png) [@Quartz](https://boards.straightdope.com/u/Quartz)
#### Post date: [April 26, 2011, 7:30pm UTC](https://boards.straightdope.com/t/moving-files-from-400-directories-into-one-directory/579799/6 "2011-04-26T19:30:33Z")

</div>

Be careful here! Make sure you don’t have any duplicate filenames.

---

<div class="post-metadata">

### Author: ![Reply](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/reply/32/15952_2.png) [@Reply](https://boards.straightdope.com/u/Reply)
#### Post date: [April 26, 2011, 7:37pm UTC](https://boards.straightdope.com/t/moving-files-from-400-directories-into-one-directory/579799/7 "2011-04-26T19:37:36Z")

</div>

> [@Quartz](#):
>
> Be careful here! Make sure you don’t have any duplicate filenames.

Good call. Using the GUI can help with this since you can tell it to automatically rename duplicates (once it finds the first one).

---

<div class="post-metadata">

### Author: ![Mangetout](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/mangetout/32/19_2.png) [@Mangetout](https://boards.straightdope.com/u/Mangetout)
#### Post date: [April 26, 2011, 7:42pm UTC](https://boards.straightdope.com/t/moving-files-from-400-directories-into-one-directory/579799/8 "2011-04-26T19:42:07Z")

</div>

The GUI ground to a halt when I tried doing it that way (I mentioned this). It wasn’t even happy when I searched for the items I wanted to delete, just because they were so numerous.

---

<div class="post-metadata">

### Author: ![Athena](https://avatars.discourse-cdn.com/v4/letter/a/35a633/32.png) [@Athena](https://boards.straightdope.com/u/Athena)
#### Post date: [April 26, 2011, 9:24pm UTC](https://boards.straightdope.com/t/moving-files-from-400-directories-into-one-directory/579799/9 "2011-04-26T21:24:30Z")

</div>

> [@Mangetout](#):
>
> The GUI ground to a halt when I tried doing it that way (I mentioned this). It wasn’t even happy when I searched for the items I wanted to delete, just because they were so numerous.

The main reason that command line stuff hasn’t been completely purged from my brain is that the GUI is just so slow when trying to do this kind of stuff. I still do dir /s to search multiple directories for files because it’s about a gazillion times faster than the GUI-based search.

---

<div class="post-metadata">

### Author: ![Reply](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/reply/32/15952_2.png) [@Reply](https://boards.straightdope.com/u/Reply)
#### Post date: [April 27, 2011, 5:16am UTC](https://boards.straightdope.com/t/moving-files-from-400-directories-into-one-directory/579799/10 "2011-04-27T05:16:40Z")

</div>

> [@Athena](#):
>
> The main reason that command line stuff hasn’t been completely purged from my brain is that the GUI is just so slow when trying to do this kind of stuff. I still do dir /s to search multiple directories for files because it’s about a gazillion times faster than the GUI-based search.

Not if you use an indexed search.

(But it’s stupid that Windows only indexes a few directories by default)

---

<div class="post-metadata">

### Author: ![Mangetout](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/mangetout/32/19_2.png) [@Mangetout](https://boards.straightdope.com/u/Mangetout)
#### Post date: [April 27, 2011, 7:30am UTC](https://boards.straightdope.com/t/moving-files-from-400-directories-into-one-directory/579799/11 "2011-04-27T07:30:20Z")

</div>

I turned off indexing because of the CPU overhead. Granted, it makes this particular task more difficult, but this is a highly exceptional circumstance. I don’t usually need to perform searches _at all_ on my computer, because I know where to find my stuff.

I wonder if indexing really would have helped here though - the recovery process created 500 subfolders filled with assorted files - the first decision I made after it had finished was that I didn’t need to bother keeping .dll files - there were several _hundred thousand_ of them. A non-indexed search found them within an acceptable time, but when I selected them and hit Shift+Delete, the system started to chug and became progressively less responsive (at the same time as not appearing to even start deleting anything). I think it just choked on the sheer magnitude of the task.

---

<div class="post-metadata">

### Author: ![Reply](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/reply/32/15952_2.png) [@Reply](https://boards.straightdope.com/u/Reply)
#### Post date: [April 27, 2011, 7:34am UTC](https://boards.straightdope.com/t/moving-files-from-400-directories-into-one-directory/579799/12 "2011-04-27T07:34:58Z")

</div>

> [@Mangetout](#):
>
> I turned off indexing because of the CPU overhead. Granted, it makes this particular task more difficult, but this is a highly exceptional circumstance. I don’t usually need to perform searches _at all_ on my computer, because I know where to find my stuff.
> 
> I wonder if indexing really would have helped here though - the recovery process created 500 subfolders filled with assorted files - the first decision I made after it had finished was that I didn’t need to bother keeping .dll files - there were several _hundred thousand_ of them. A non-indexed search found them within an acceptable time, but when I selected them and hit Shift+Delete, the system started to chug and became progressively less responsive (at the same time as not appearing to even start deleting anything). I think it just choked on the sheer magnitude of the task.

No, indexing wouldn’t have helped here – in the time it’d take to search and index all the files, you could instead just delete them as you go (as you’ve done).

But for general use, using indexed search vs browsing can be much faster as long as you remember what you call things or how to search for them. (For example, typing part of a song name instead of browsing to music then artist then album then song)

ETA: Sorry, I realize what you’re saying now. I misread Athena’s comment and didn’t realize it applied specifically to this case. Oops :smack:

---

<div class="post-metadata">

### Author: ![Athena](https://avatars.discourse-cdn.com/v4/letter/a/35a633/32.png) [@Athena](https://boards.straightdope.com/u/Athena)
#### Post date: [April 27, 2011, 12:30pm UTC](https://boards.straightdope.com/t/moving-files-from-400-directories-into-one-directory/579799/13 "2011-04-27T12:30:45Z")

</div>

> [@Reply](#):
>
> Not if you use an indexed search.
> 
> (But it’s stupid that Windows only indexes a few directories by default)

Then you have to put up with slow & buggy Windows indexing running all the time. And that’s from a pro-MS person who generally likes Windows. But I’ve never had any luck with their indexing (or anyone else’s, for that matter. Google Desktop really got slow after running it a few months.)

Granted, it seems better in Windows 7 (on a mega machine with tons of memory) but still, the DOS search isn’t un-handy enough that I want to turn on Windows indexing for my entire machine.
