gpt4 book ai didi

linux - 将 mp3 文件从一个目录移动到按艺术家、专辑、歌曲名称分开的目录

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:27:12 26 4
gpt4 key购买 nike

我在一个文件夹中备份了所有 mp3 文件。

会不会有一个 bash 命令来自动移动他们自己的即时创建的乐队专辑标题目录中的所有文件?

正如您在图片中看到的,破折号之前的第一个单词是艺术家姓名,然后是专辑名称,然后是歌曲名称。

enter image description here

示例:艺术家或乐队 - 专辑名称 - 歌曲名称.mp3。

所以最后,文件将处于以下层次结构中。

Artist or band1/    
album title1/
name of song.mp3
album title2/
name of song.mp3

Artist or band2/
album title1/
name of song.mp3

等等。

最佳答案

我不知道直接执行此操作的命令,但这是我解决此问题的方法(使用 Perl):

perl -MFile::Path -we 'for my $file (glob "*.mp3") { my ($artist, $album, $title) = split / - /, $file, 3; mkpath "$artist/$album"; my $new = "$artist/$album/$title"; rename $file, $new or warn "$file -> $new: $!\n"; }'

或稍微更具可读性:

perl -MFile::Path -we '
for my $file (glob "*.mp3") {
my ($artist, $album, $title) = split / - /, $file, 3;
mkpath "$artist/$album";
my $new = "$artist/$album/$title";
rename $file, $new or die "$file -> $new: $!\n";
}'

关于linux - 将 mp3 文件从一个目录移动到按艺术家、专辑、歌曲名称分开的目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37902910/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com