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

This topic contains 4 replies, has 3 voices, and was last updated by  Kevyn 4 months ago.

  • Author
    Posts
  • #77317

    Del
    Participant

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

  • #77320

    Kevyn
    Participant

    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.

  • #77323

    Kevyn
    Participant

    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.

    • #77331

      Michael Halpin
      Participant

      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.

    • #77332

      Kevyn
      Participant

      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.

You must be logged in to reply to this topic.