steelthunder
steelthunder

Reputation: 438

copying all mp3s recursively into a single folder in Windows

I have a bunch of music on my windows machine that is organized in folders by artist and then by album. I would like to copy all of the mp3s recursively from all the folders and sub-folders under a main directory into a single location.

Can this be done with windows command line?

Upvotes: 0

Views: 2198

Answers (4)

J murray
J murray

Reputation: 1

Assuming your directories are structured artist/album/*.mp3:

Make a directory for the copied files

mkdir new

Go to your music directory

cd g:/music

Append your .mp3 with three wildcard characters * separated by \:

cp "*/*/*.mp3" "g:/new"

Upvotes: 0

Abu.Rajih22
Abu.Rajih22

Reputation: 13

in windows console the command is

xcopy "*".mp3 $from $to

$from it should be the path of your destination source

$to it should be the new path for your source

Upvotes: 0

Your code inspired me to do a similar task. I move the directories and the files contain a list of file format towards my new destination. Then I delete the empty folders afterwards.

$Source = 'D:\Téléchargements'
$Dest = 'D:\Musique'
# List of file format
$File = '*.mp3', '*.flac'

Get-ChildItem "$Source\*" -Include $File -Recurse –force -ErrorAction SilentlyContinue | ForEach{
    $FilePath = $_.DirectoryName
    # File directly in source dir
    If ($FilePath -eq $Source) { Move-Item $_.FullName -Destination $Dest -Force }
    Else {
        $DestPath = ("$FilePath\") -Replace [Regex]::Escape($Source), $Dest
        If ( !(Test-Path $DestPath) ) { New-Item -ItemType Directory -Path $DestPath -Force | Out-Null }
        Move-Item $_.FullName -Destination $DestPath -Force
        # Delete empty dir 
        If ((Get-ChildItem $FilePath).count -eq 0) { Remove-Item $FilePath -Force}
    }
}

Upvotes: 0

gaby
gaby

Reputation: 306

let's say that we have the following structure

  • c:\temp\1\musicfile.mp3
  • c:\temp\2\goodmusicfile.mp3
  • c:\temp\3\verygoodfile.mp3
  • c:\temp\whatever\what.mp3

and we want to copy all those file to a single directory in

  • c:\temp\all

create a bat file inside the c:\temp\ for example copyallmp3.bat and write the following code

for /R "C:\temp" %%i in (*.mp3) do xcopy "%%i" "C:\temp\all" /y

run copyallmp3.bat. If you navigate to c:\temp\all you will see all your 4 mp3 files.

If you want the final result to be something like (recursively)

  • c:\temp\all\1\musicfile.mp3
  • c:\temp\all\2\goodmusicfile.mp3
  • c:\temp\all\3\verygoodfile.mp3
  • c:\temp\all\whatever\what.mp3

use the following code in powershell

$Source = 'C:\temp'
$Files = '*.mp3'
$Dest = 'C:\temp\all'
Get-ChildItem $Source -Filter $Files -Recurse | ForEach{
    $Path = ($_.DirectoryName + "\") -Replace [Regex]::Escape($Source), $Dest
    If(!(Test-Path $Path)){New-Item -ItemType Directory -Path $Path -Force | Out-Null
    Copy-Item $_.FullName -Destination $Path -Force
}}

Upvotes: 1

Related Questions