# How to divide a folder with over a million files into smaller folders

**URL:** https://forums.powershell.org/t/how-to-divide-a-folder-with-over-a-million-files-into-smaller-folders/9180
**Category:** PowerShell Help
**Created:** [August 15, 2017, 2:44pm UTC](https://forums.powershell.org/t/how-to-divide-a-folder-with-over-a-million-files-into-smaller-folders/9180 "2017-08-15T14:44:47Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![del-mo](https://avatars.discourse-cdn.com/v4/letter/d/a5b964/32.png) [@del-mo](https://forums.powershell.org/u/del-mo)
#### Post date: [August 15, 2017, 2:44pm UTC](https://forums.powershell.org/t/how-to-divide-a-folder-with-over-a-million-files-into-smaller-folders/9180/1 "2017-08-15T14:44:47Z")

</div>

I have a shared folder with over a million files into it, is there a way to split the contents into many smaller folders ?

---

<div class="post-metadata">

### Author: ![miracles1315](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@miracles1315](https://forums.powershell.org/u/miracles1315)
#### Post date: [August 15, 2017, 3:46pm UTC](https://forums.powershell.org/t/how-to-divide-a-folder-with-over-a-million-files-into-smaller-folders/9180/2 "2017-08-15T15:46:33Z")

</div>

You might try New-Item to create additional directories to split/move the items into, and then use Move-Item to move certain items to the folders/subfolders you create. With a million files, you’ll probably want to use the -Filter parameter, of the Move-Item cmdlet, to get a subset of the files that you want to move to a particular folder.

---

<div class="post-metadata">

### Author: ![miracles1315](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@miracles1315](https://forums.powershell.org/u/miracles1315)
#### Post date: [August 15, 2017, 3:49pm UTC](https://forums.powershell.org/t/how-to-divide-a-folder-with-over-a-million-files-into-smaller-folders/9180/3 "2017-08-15T15:49:49Z")

</div>

You can use the same -Filter parameter on Get-Item, storing the results into a variable, and then dumping out the variable to make sure you will be moving the items you want to move to a particular folder/subfolder. You can then pipe the variable to the Move-Item cmdlet.

---

<div class="post-metadata">

### Author: ![micheal100](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/micheal100/32/438_2.png) [@micheal100](https://forums.powershell.org/u/micheal100)
#### Post date: [August 15, 2017, 5:13pm UTC](https://forums.powershell.org/t/how-to-divide-a-folder-with-over-a-million-files-into-smaller-folders/9180/4 "2017-08-15T17:13:04Z")

</div>

I would think using a variable may use a lot of memory, try piping from the get-item directly to the move-item, it should be more memory efficient.

---

<div class="post-metadata">

### Author: ![miracles1315](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@miracles1315](https://forums.powershell.org/u/miracles1315)
#### Post date: [August 15, 2017, 5:47pm UTC](https://forums.powershell.org/t/how-to-divide-a-folder-with-over-a-million-files-into-smaller-folders/9180/5 "2017-08-15T17:47:13Z")

</div>

That’s definitely possible, but before running a Get/Move script, with guns-a-blazing, on a million files it’s good to verify that the right set of objects will be affected by the Move-Item cmdlet. If the filter can be fine-tuned enough, for a test, that would be the best thing before running the code on the full set.

---

<div class="post-metadata">

### Author: ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)
#### Post date: [May 16, 2024, 8:38pm UTC](https://forums.powershell.org/t/how-to-divide-a-folder-with-over-a-million-files-into-smaller-folders/9180/6 "2024-05-16T20:38:20Z")

</div>


