Skwire, unless you or someone else wants to add anything, this one looks solved.-nkormanik
Anyway
, here a script, done with PowerShell, just for fun and because PoSh is there already.
(Tested with PoSh v4, but forced to behave like v2. Write
$PSVersionTable to get your version)
I have 600,000 midi files, in a single folder.
I'd like to move/organize into folders. 100 midi files per new folder. Sorted by size of files.
So, the smallest 100 midi files will go into, say, folder 0001.
Second 100 smallest midi files will go into folder 0002.
Etc.
Will need to create all the required folders.
-nkormanik
With PowerShell:
Open a PowerShell console in your "single folder" with the "600,000 midi files".
---
If wanted, Create some test files (with random names and different size) to test my script:
1..
200|%{ fsutil file createnew
([System.IO.Path
]::GetRandomFileName
()) $_ | Out-Null}
---
Move every ten files (sorted by size) to a new created sub folder:
(Change "-lt 10" to the wanted amount, like "-lt 100")
ls|?{!$_.PSIsContainer
}|sort length
|%{$C=0;$I
=1}{$C++;
if($C-lt10){mkdir
$I -ea
0|Out-Null;
Move $_ $I}else{Move $_ $I;$C
=0;$I
++}}
---
The same Move-script, but as long version, with official command names and such:
# DIR folder:
Get-ChildItem |
# Files only, no directories:
Where-Object{ -not $_.PSIsContainer
} | # Sort by file size:
Sort-Object -Property length |
# For Each File from DIR Do:
ForEach-Object
# One time, common for all files, at the beginning, set counter:
-Begin{ $FileCount=0; $LotFolder=1 }
# For each individual file:
-Process{ $FileCount++;
# break/reset at every max count, here 10:
if($FileCount -lt 10){
# Create sub folder, suppress error message on existing folder (ErrorAction), suppress success message too (>NUL):
New-Item -path $LotFolder -ItemType directory -ErrorAction SilentlyContinue|Out-Null;
# Move current file to sub folder:
else{
# On last file in set, Move current file to sub folder and adjust counter:
Move $_ $LotFolder;
$FileCount=0;
$LotFolder++} }
# One time, common for all files, at the very end:
-End {"Done!"}
.