我正在尝试运行一个循环,让您选择一个目录,然后从该目录上传文件。当您按“取消”时,我无法让循环整齐地停止(没有错误)
def search_audit():
chosen_dir = tkFileDialog.askdirectory(parent=root, initialdir=os.sep, title='please select a dir')
return chosen_dir
def splunk_uploader(ip, port):
#code to connect socket
chosen_dir = search_audit()
while chose_dir != 'NULL': #This won't work
for path, subdirs, files in os.walk(chosen_dir):
for filename in files:
c = os.path.join(path, filename)
f = open(c, 'r')
while True:
#code sends file
s.send(line) #line errno points to, works fine first directory chosen
chosen_dir = search_audit()
s.close()
我希望程序运行并要求一个目录,直到我按下取消。它一直要求输入目录并运行,但是当我按下取消时,它会上传整个 C: 驱动器