【问题标题】:copying all mp3s recursively into a single folder in Windows将所有 mp3 递归复制到 Windows 中的单个文件夹中
【发布时间】:2015-03-26 00:51:29
【问题描述】:

我的 Windows 机器上有一堆音乐,它们按艺术家和专辑组织在文件夹中。我想将主目录下所有文件夹和子文件夹中的所有 mp3 递归复制到一个位置。

这可以用windows命令行完成吗?

【问题讨论】:

  • 我推荐使用powershell来做这个,它预装了windows。
  • 谢谢。你能告诉我语法是什么吗?

标签: windows-console


【解决方案1】:

假设我们有以下结构

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

我们希望将所有这些文件复制到

中的单个目录
  • c:\temp\all

在 c:\temp\ 中创建一个 bat 文件,例如 copyallmp3.bat 并编写以下代码

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

运行 copyallmp3.bat。 如果您导航到 c:\temp\all,您将看到所有 4 个 mp3 文件。

如果您希望最终结果类似于(递归)

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

在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
}}

【讨论】:

    【解决方案2】:

    您的代码启发了我做类似的任务。我将目录和文件包含到我的新目的地的文件格式列表。然后我之后删除空文件夹。

    $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}
        }
    }
    

    【讨论】:

      【解决方案3】:

      在 windows 控制台中的命令是

      xcopy "*".mp3 $from $to
      

      $from它应该是你的目标源的路径

      $to它应该是你的来源的新路径

      【讨论】:

        【解决方案4】:

        假设您的目录是结构化的artist/album/*.mp3

        为复制的文件创建一个目录

        mkdir new
        

        转到您的音乐目录

        cd g:/music
        

        在您的.mp3 后面加上三个通配符*,以\ 分隔:

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

        【讨论】:

        • 请参阅formatting help 了解有关如何使用 Stack Overflow 的降价语法的说明。欢迎来到 Stack Overflow!
        • 根据@PranavHosangadi 的说明,我已编辑您的帖子以改进格式。请查看我所做的编辑,以便您将来可以将类似的格式应用于您自己的帖子。再次欢迎您。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-10-25
        • 1970-01-01
        • 2017-10-03
        • 1970-01-01
        • 2015-01-20
        • 2021-04-09
        • 1970-01-01
        相关资源
        最近更新 更多