Home > database >  How to sort e.g. 200 folders into 8 parent folders of 25 subfolders each? (Windows 10)
How to sort e.g. 200 folders into 8 parent folders of 25 subfolders each? (Windows 10)

Time:09-23

I have 200 individual folders with 50 files inside each folder. I would like to sort these 200 individual folders into 8 parent folders of 25 subfolders each, whilst retaining all the files inside the subfolders.

Ideally, the naming structure of the parent folders should follow a sequential pattern based on a phrase (So e.g. "rvolkov Files 1", "rvolkov Files 2", etc).

I have tried to find powershell script for the above, but it seems to only work with files and not folders, so I haven't been able to utilise it (here)

How can I do this in Windows 10? If it helps, the individual folders are named after barcodes, so the first few digits are the same.

Thank you in advance

CodePudding user response:

According to what I assume is your question, this is a possible solution:

# GeneralParameters
$dir         = "C:\yourdirhere"
$ParentDepth = 8
$FolderCount = 25

$dirs        = gci $dir -Directory
cd $dir         #Makes it easier to debug and read the code, not entirely necessary.
$SubCounter = 0

for ($ParentCounter=1;$ParentCounter -le $ParentDepth;$ParentCounter   ) {
    mkdir "Parent$ParentCounter"
    for ($i=1;$i -le $FolderCount; $i  ) {
        Move-Item -Path $dirs[$SubCounter].FullName -Destination "Parent$ParentCounter"
        $SubCounter  
    }
}
  • Related