在此代码中,我检查文件夹是否存在,如果不存在则创建它,但是,我使用尾随空格创建它,因为我无法+ "\"
在\
. 我如何添加NewFolderPath
没有这个空间?
dir_carteiras = r"C:\Users\GuilhermeMachado\Documents\Carteiras"
test = os.listdir(dir_carteiras)
for item in test:
if item.endswith(".jpg"):
os.remove( os.path.join(dir_carteiras, item))
today=datetime.date.today()
five_day=datetime.timedelta(days=-1)
d_N1=today+five_day
d_N1_ = d_N1.strftime('%Y.%m.%d')
NewFolderPath = dir_carteiras+"\Historico"+"\ "+d_N1_
isFile = os.path.exists(NewFolderPath)
您正在寻找os.path.join()
. 它会为您插入正确的符号。
NewFolderPath = os.path.join(dir_carteiras,"Historico",d_N1_)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句