在Linux路径和文件名中转义空格 [英] escape whitespaces in linux path and file names

查看:926
本文介绍了在Linux路径和文件名中转义空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的清理我的系统。和往常一样,我正在试图做到这一点蟒蛇的方式,
,所以我正在清理我的音乐库中的重复。现在我正在试图找到一个模式
重新模块来转义所有的空格和特殊字符。但不幸的是我无法找到可用的东西。这是一些剪辑的重复列表,我使用linux cli工具生成的名为fdupes:
$ b $ pre $ ./ D / dominik eulberg / 01 bionik / 01 bionik(guy gerber remi.m4p
./D/dominik eulberg / 05 dominik eulberg / 01 bionik / 01 bionik(guy gerber remi.m4p

./N/Nightmares在蜡/吸烟者喜悦/ 05 - Stars.mp3
./N/Nightmares在蜡或吸烟者喜悦/ NOW - 吸烟者delight_04.MP3

./N/Nightmares在蜡或吸烟者喜悦/ 13 - 我的感觉(好).mp3
./N/Nightmares On Wax / Smokers Delight / NOW - smokers delight_13.MP3
$ b $ ./N/Nightmares On Wax /吸烟者喜悦/ 16 - 冈比亚通过Vagatorbeach.mp3
./N/Nightmares在蜡/吸烟者喜悦/现在 - 吸烟者delight_16.MP3
./S/Stupidozid/Morast_Beatz/12。Morast Beatz - 英国皇家空军 - von TeeK.mp3
./S/stupidozid_12/Morast_Beatz-Startproblem_und_Endloesung_2012/12。Morast Beatz - 英国皇家空军 - von TeeK.mp3

./S/Slackers/Folder.jpg
./S/Slackers/AlbumArt_{4CC84D50-8EED-415A-9ED3-7144D9AE90F2}_Large.jpg

./S/Slackers/AlbumArtSmall.jpg
./S/Slackers/AlbumArt_{4CC84D50-8EED-415A-9ED3-7144D9AE90F2}_Small.jpg

./L/Led Zeppelin - 唱片/ Led Zeppelin - Led Zeppelin III / AlbumArt_ {C9AAD432-BF70-4AFB-97C6-14734CD290B8} _Large.jpg
./L/Led Zeppelin - 唱片分目/ Led Zeppelin - Led Zeppelin III /Folder.jpg


解决方案

使用 pipes.quote 功能。在Python 3中,这个函数被重新命名为 shlex.quote 。这些函数引用一个字符串,以便它可以安全地用作shell命令的一部分。


i actually cleaning up my system. And as usual i am trying to do it the python way, so i am cleaning up duplicates in my Music library. And now i am trying to find a pattern for re module to escape all whitespace and special characters. But unfortunately i was unable to find something useable. This is some snipped of the duplicates list i generated with linux cli tool called "fdupes" :

./D/dominik eulberg/01 bionik/01 bionik (guy gerber remi.m4p
./D/dominik eulberg/05 dominik eulberg/01 bionik/01 bionik (guy gerber remi.m4p

./N/Nightmares On Wax/Smokers Delight/05 - Stars.mp3
./N/Nightmares On Wax/Smokers Delight/NOW - smokers delight_04.MP3

./N/Nightmares On Wax/Smokers Delight/13 - What I'm Feelin (Good).mp3
./N/Nightmares On Wax/Smokers Delight/NOW - smokers delight_13.MP3

./N/Nightmares On Wax/Smokers Delight/16 - Gambia Via Vagatorbeach.mp3
./N/Nightmares On Wax/Smokers Delight/NOW - smokers delight_16.MP3
./S/Stupidozid/Morast_Beatz/12. Morast Beatz - RAF - von TeeK.mp3
./S/stupidozid_12/Morast_Beatz-Startproblem_und_Endloesung_2012/12. Morast Beatz - RAF - von TeeK.mp3

./S/Slackers/Folder.jpg
./S/Slackers/AlbumArt_{4CC84D50-8EED-415A-9ED3-7144D9AE90F2}_Large.jpg

./S/Slackers/AlbumArtSmall.jpg
./S/Slackers/AlbumArt_{4CC84D50-8EED-415A-9ED3-7144D9AE90F2}_Small.jpg

./L/Led Zeppelin - Discography/Led Zeppelin - Led Zeppelin III/AlbumArt_{C9AAD432-BF70-4AFB-97C6-14734CD290B8}_Large.jpg
./L/Led Zeppelin - Discography/Led Zeppelin - Led Zeppelin III/Folder.jpg

解决方案

Use the pipes.quote function. In Python 3 this function was renamed to shlex.quote. These functions quote a string so that it can safely be used as part of a shell command.

这篇关于在Linux路径和文件名中转义空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆