[英]How to create folder without trailing white space?
在此代码中,我检查文件夹是否存在,如果不存在,则创建它,但是,我使用尾随空格创建它,因为我无法在\\
前面使用引号执行+ "\\"
. 如何在没有此空间的情况下添加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_)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.