I’m trying to run a loop that makes you choose a directory, then upload files from that directory. I cant get the loop to stop neatly (without errors) when you press ‘cancel’
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()
What I was hoping is for the program to run and ask for a directory until I pressed cancel. It keeps asking for a direcotry and runs, but when I press cancel, it uploads entire C: drive
Check the value against
Nonerather than'NULL'. As your code is written now, it will only stop of they choose a file literally namedNULL.