Need to search & group files

geno11x11

New Member
Joined
Apr 16, 2026
Messages
1
Background: I have a large .mp3 & .flac music library.

I need to search for files & directories in groups of 1300 in order to copy them to individual USB drives i.e., group #1 files 1 thru 1300; group #2 files 1301 to 2600, etc.

Why? Because the mp5 media player in my vehicles has a song randomize limit of 1300 files. Although 1300 is a large number, I'd like to have numbered USB drives containing more groups of files for variety or for listening to categories such as Christmas songs during the holiday.

Objective:
I have accomplished this task in the past in an inefficient and awkward way: Using file explorer, I initiate the search and the result window fills to a particular number, say 100 files. I select the top file, scroll until the screen fills again, multiplying the each screen set by the number of windows displayed, until I reach 1300 and then <shift> click the final file to select the group and copy to the USB drive. It is an error-prone and time consuming method; a mispositioned cursor deselects the entire group requiring a restart. Imagine the frustration if you're working on group #3 and the selection limit for the previous group is lost; the entire process has to be started again from scratch.

A great solution would be the file search results were accompanied by a number to the left of the file name. I could then select specific numbered files, but file explorer does not have that functionality.

I've been scouring the Internet for a better file manager or search/select strategy. Do you have a more efficient solution?
 
Hi geno11x11,
Yes — there is a much better way than selecting files manually in File Explorer.

Best solution​

Use PowerShell to:
  1. Scan your music library for .mp3 and .flac files.
  2. Sort them in a fixed order.
  3. Split them automatically into folders of 1300 files each.
  4. Copy those grouped folders wherever you want.
That gives you folders like:
  • Group_001
  • Group_002
  • Group_003
Then you can copy each group to a separate USB drive.

Why this is better​

  • No manual counting
  • No accidental deselection
  • Repeatable
  • Works on very large libraries
  • Keeps your original files untouched

Important note first​

If you have duplicate filenames in different folders, a flat copy can overwrite files.
The script below avoids that by preserving the original folder structure inside each group.

Steps​

1. Create a destination folder​

For example:
D:\Music_Groups

2. Open PowerShell​

Press Win + X and choose Windows PowerShell or Terminal.

3. Edit and run this script​

Change the $Source and $Destination paths first.
Code:
$Source = "D:\Music"
$Destination = "D:\Music_Groups"
$BatchSize = 1300

$files = Get-ChildItem -Path $Source -Recurse -File |
    Where-Object { $_.Extension -in ".mp3", ".flac" } |
    Sort-Object FullName

if (!(Test-Path $Destination)) {
    New-Item -ItemType Directory -Path $Destination | Out-Null
}

for ($i = 0; $i -lt $files.Count; $i++) {
    $groupNumber = [math]::Floor($i / $BatchSize) + 1
    $groupFolder = Join-Path $Destination ("Group_{0:D3}" -f $groupNumber)

    $relativePath = $files[$i].DirectoryName.Substring($Source.Length).TrimStart('\')
    $targetFolder = if ($relativePath) {
        Join-Path $groupFolder $relativePath
    } else {
        $groupFolder
    }

    if (!(Test-Path $targetFolder)) {
        New-Item -ItemType Directory -Path $targetFolder -Force | Out-Null
    }

    Copy-Item -LiteralPath $files[$i].FullName -Destination $targetFolder
}

Write-Host "Done. Total files processed: $($files.Count)"
Write-Host "Total groups created: $([math]::Ceiling($files.Count / $BatchSize))"

What this does​

  • Finds all .mp3 and .flac files under your music folder
  • Sorts them by full path
  • Puts files 1-1300 into Group_001
  • Puts files 1301-2600 into Group_002
  • Continues until finished

Example result​

If your source is:
D:\Music
You might end up with:
  • D:\Music_Groups\Group_001\...
  • D:\Music_Groups\Group_002\...
  • D:\Music_Groups\Group_003\...
Then just copy Group_001 to USB #1, Group_002 to USB #2, and so on.

If you want a numbered file list first​

If you want to see exactly which file is number 1, 1300, 1301, etc., run this first:
Code:
$Source = "D:\Music"

$files = Get-ChildItem -Path $Source -Recurse -File |
    Where-Object { $_.Extension -in ".mp3", ".flac" } |
    Sort-Object FullName

$numbered = for ($i = 0; $i -lt $files.Count; $i++) {
    [PSCustomObject]@{
        Number = $i + 1
        FullName = $files[$i].FullName
    }
}

$numbered | Export-Csv "D:\Music_File_List.csv" -NoTypeInformation
That creates a CSV you can open in Excel and see the exact numbering.

Safer test first​

Before running it on the full library:
  1. Make a small test folder with 20 to 30 music files.
  2. Change $Source to that folder.
  3. Change $BatchSize to something small like 5.
  4. Confirm the grouping looks right.
  5. Then run it on the full library.

One more thing to consider​

If you want to keep albums together instead of splitting purely by file count, that is also possible.
The logic is slightly different because it groups by folder/album rather than by individual tracks.
If you want, I can post a second script that does either of these:
  1. Split by individual song count
  2. Keep album folders together as much as possible