展平目录层次结构,在新目录名称中保留目录名称

aksh1618

我基本上想从这里开始:

.
├── Alan Walker
│   ├── Different World
│   │   ├── 01 Intro.mp3
│   │   ├── 02 Lost Control.mp3
│   │   └── cover.jpg
│   └── Same World
│       ├── 01 Intro.mp3
│       └── 02 Found Control.mp3
├── Aurora
│   └── Infections Of A Different Kind Step 1
│       ├── 01 Queendom.lrc
│       ├── 02 Forgotten Love.lrc
│       └── 03 Gentle Earthquakes.mp3
└── Guns N' Roses
    └── Use Your Illusion I
        ├── 01 Right Next Door To Hell.lrc
        ├── 01 Right Next Door To Hell.mp3
        ├── 02 Dust N' Bones.lrc
        └── 02 Dust N' Bones.mp3

对此:

.
├── Alan Walker - Different World
│   ├── 01 Intro.mp3
│   ├── 02 Lost Control.mp3
│   └── cover.jpg
├── Alan Walker - Same World
│   ├── 01 Intro.mp3
│   └── 02 Found Control.mp3
├── Aurora - Infections Of A Different Kind Step 1
│   ├── 01 Queendom.lrc
│   ├── 02 Forgotten Love.lrc
│   └── 03 Gentle Earthquakes.mp3
└── Guns N' Roses - Use Your Illusion I
    ├── 01 Right Next Door To Hell.lrc
    ├── 01 Right Next Door To Hell.mp3
    ├── 02 Dust N' Bones.lrc
    └── 02 Dust N' Bones.mp3

我找不到的现有解决方案中都没有包含重命名目录本身。能够使用zmv做到这一点真是太好了,但是我不知道该怎么做。

吉勒斯“别再邪恶了”

sh

未经测试:

zmv -Q '(*)/(*)(/)' '$1 - $2'
rmdir -- *(/^F)

第二行删除所有空目录,即使以前没有文件的目录也是如此。可以使用自定义mv包装器解决此问题,该包装器记录将内容从哪个目录移出。

请注意,这会遍历到当前目录中目录的符号链接。

Linux重命名实用程序

未经测试。

rename / ' - ' */*/
rmdir -- */ 2>/dev/null

请注意,这会遍历到当前目录及其子目录中目录的符号链接。第二行删除所有空目录,即使以前没有文件的目录也是如此。

Perl重命名脚本

未经测试。

prename 's~/~ - ~' */*/
rmdir -- */ 2>/dev/null

请注意,这会遍历到当前目录及其子目录中目录的符号链接。第二行删除所有空目录,即使以前没有文件的目录也是如此。

这是一种更复杂的方法,该方法仅删除从其重命名的目录。再次,未经测试。

prename 's~([^/]+)/~$1 - ~ and ++$d{$1}; END {map {rmdir} keys %d}' */*/

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章