gpt4 book ai didi

python - 转义 linux 路径和文件名中的空格

转载 作者:太空狗 更新时间:2023-10-29 21:39:54 38 4
gpt4 key购买 nike

我实际上是在清理我的系统。和往常一样,我试图用 python 的方式来做,所以我正在清理音乐库中的重复项。现在我正试图找到一种模式为 re 模块转义所有空格和特殊字符。但不幸的是我找不到有用的东西。这是我使用名为“fdupes”的 linux cli 工具生成的重复列表的一部分:

./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

最佳答案

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

关于python - 转义 linux 路径和文件名中的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24844707/

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