我有一个创建文件的脚本,但我想查看该文件是否存在,以便将其移动到其他目录.我得到的问题是它在一个目录级别看起来太高了.
Ex fileIn = a/b/c/d它在d中查找,而不是c
print directory + " go up one!!!"
os.path.dirname(os.path.dirname(directory)) # this specific line does nothing
if f.endswith("_edited.xml"):
print "true"
else:
print "false"
#shutil.copy2(f, aEdit)
Run Code Online (Sandbox Code Playgroud)
如果使用os.getcwd(),您可以查看当前正在使用的目录.
您想用来os.chdir(PATH)更改目录.
更改目录的方法是使用 ..
>>> print(os.getcwd())
C:\Python34
>>> os.chdir('..')
>>> print(os.getcwd())
C:\
Run Code Online (Sandbox Code Playgroud)