1
我想運行一個循環,讓你選擇一個目錄,然後從該目錄上傳文件。我不能讓循環停止整齊地(沒有錯誤),當您按下「取消」tkFileDialog.askdirecotry循環,直到'取消' - tkinter python
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()
我希望是要運行的程序和要求一個目錄中,直到我按下了取消。它會一直詢問一個direcotry並運行,但是當我按取消時,它會上傳整個C:驅動器
謝謝,解決了它!也適用於#while chosen_dir!='' – MrEwok