当我打开一个文件时,我必须指定它所在的目录。有没有办法指定使用当前目录而不是写出路径名?我使用的是:
source = os.listdir("../mydirectory")但是,只有将程序放在名为"mydirectory“的目录中,它才能运行。我希望程序在它所在的目录中工作,无论它的名称是什么。
def copyfiles(servername):
source = os.listdir("../mydirectory") # directory where original configs are located
destination = '//' + servername + r'/c$/remotedir/' # destination server directory
for files in source:
if files.endswith("myfile.config"):
try:
os.makedirs(destination, exist_ok=True)
shutil.copy(files,destination)
except:发布于 2017-06-24 01:03:10
尝试:
os.listdir('./')或者:
os.listdir(os.getcwd())https://stackoverflow.com/questions/44726578
复制相似问题