date_string = r'C:\apache-tomcat-8.5.16\g\after\said\%s' % (now.strftime('%Y.%b\%d'))
if os.path.dirname('C:\apache-tomcat-8.5.16\g\after\said\%s' % (now.strftime('%Y.%b\%d'))):
print "File exist"
#sizefile = "".join("cd", date_string)
#print sizefile
sathya = os.system('dir /s ' +date_string)
print(sathya)
else:
print "no"
输出是:
File exist
Volume in drive C has no label.
Volume Serial Number is F497-220A
File Not Found
1
C:\Users\Administrator\Desktop>
请帮忙。
我通过使用子流程解决了这个问题,找到下面的代码;
date_string = r''C:\apache-tomcat-8.5.16\g\after\said\%s' % (now.strftime('%Y.%b\%d'))
cmd = "dir /s"+" "+date_string+ ">> gad"
subprocess.call(cmd , shell=True)
请使用subprocess而不是os.system()。