escape whitespaces in linux path and file names

匿名 (未验证) 提交于 2019-12-03 08:54:24

问题:

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 

回答1:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!