我正在创建一个大量下载osu的程序!当我突然意识到我并没有处理所有的百分比编码时,beatmaps就会出现。现在,我有大量重复项,需要快速删除。
class ThisNameIsIrrelevant:
def cleanPath(self, path=None):
if not path:
print("Missing required argument: 'localpath'")
return
badchars = ["%21","%23","%24","%25","%26","%27","%28","%29","%2A",
"%2B","%2C","%2F","%3A","%3B""%3D","%3F","%40","%5B","%5D"]
folders = []
for r, d, f in os.walk(path): # where R=ROOT, D=DIRECTORIES,F=FILES
for folder in d:
folders.append(os.path.join(r, folder))
for f in folders:
for item in badchars: # checking for percent-encoding
if item in f:
os.remove(f)
print(f"{f} removed")
ThisNameIsIrrelevant().cleanPath("C:\\Users\\xupaii\\AppData\\Local\\osu!\\Songs") # error here - PermissionError: [WinError 5] Access is denied:
我希望此操作仅遍历每个文件夹,将badchars
中的项目与文件夹名称进行比较,如果匹配则将其删除。但是,即使以管理员身份运行VScode,也会出现此错误。该文件也未打开。