Reputation: 438
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
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
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
Reputation: 1
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
Reputation: 306
let's say that we have the following structure
and we want to copy all those file to a single directory in
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)
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