在 python 中使用 os.rename 并得到 '[Errno 2] No such file or directory'
完整代码:
import os
from string import digits # digits are one of 0123456789
path = "/Users/xxx/Documents/version-control/secret-msg/prank/"
l = os.listdir(path) # returns list of files in folder
for o in l: #o for 'original'
c = o.lstrip(digits) # c for 'clean', without leading digits; lstrip = left strip - so left strip any digit
if (o != c):
os.rename (o, c) #rename original filename to clean one
print o + '-> ' + c # for debug only