Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Jul 2015
    Thanked 0 Times in 0 Posts

    Exclamation Moving a certain # of files from thousands to a new folder?

    OK.... Here is my problem:

    I am a DJ and I have over the years and years collected or converted many many .mp3 files. In an attempt to reorganize my extremely cluttered music drive I placed all my .mp3 files into 1 root directory (P:\Music). I was going to use MusicBrains Picard to retag and organize the files but it crashes on both computers when adding a folder with more than 1,000 .mp3 files. I have 162,518 .mp3 files in that folder.....

    So here is what I want to do....

    I want to take the 1st 1,000 .mp3 files and move them to (P:\Music\1) then repeat the process and move that 1,000 .mp3 files to (P:\Music\2) and so on and so on...

    I am looking for a batch file to run to do this for me automatically.

    I tried powershell and that failed (or should I say had NO effect and no errors - so I don't know what went wrong there).
    This is the PowerShell Script, that I got from someone else and tried, that did nothing

    $dirBase = "P:\Music\"
    $dirProc1 = "P:\Music\1\"
    $dirProc2 = "P:\Music\2\"
    $dirProc3 = "P:\Music\3\"
    $dirProc4 = "P:\Music\4\"
    cd $dirBase
    $directoryInfo1 = Get-ChildItem $dirProc1 | Measure-Object
    $directoryInfo2 = Get-ChildItem $dirProc2 | Measure-Object
    $directoryInfo3 = Get-ChildItem $dirProc3 | Measure-Object
    $directoryInfo4 = Get-ChildItem $dirProc4 | Measure-Object
    if ($directoryInfo1.count -eq 0) {
        MoveFiles $dirBase $dirProc1
    if ($directoryInfo2.count -eq 0) {
        MoveFiles $dirBase $dirProc2
    if ($directoryInfo3.count -eq 0) {
        MoveFiles $dirBase $dirProc3
    if ($directoryInfo4.count -eq 0) {
        MoveFiles $dirBase $dirProc4
    function MoveFiles([string]$srcDir, [string]$dest)
        $FileLimit = 1000    
        $Counter = 0
        [IO.Directory]::EnumerateFiles($srcDir) | Where-Object {$Counter -lt $FileLimit} | %{ 
        #Get-ChildItem $srcDir | Select-Object -first $FileLimit | %{ 
            Move-Item $_ -destination $dest
    Please someone help me out here! With 162,000+ .mp3s sitting here selecting 1,000 files manually (of course using Shift+LMB) then cut and paste into folder is so time consuming....

    Thank you in advance!!!!

  2. #2
    WS Lounge VIP
    Join Date
    Dec 2009
    Thanked 1,116 Times in 1,039 Posts
    Your looping isn't right. Try a FOREACH statement instead.

    $FileLimit = 1000
    $Counter = 0
    $FileList = [IO.Directory]::EnumerateFiles($srcDir)

    Foreach ($File in $FileList) {
    if ($Counter < $FileLimit) {
    Move-Item $File -destination $dest

    Note: I've not tested this.

    cheers, Paul

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts