I am working on a python program that will prompt the user to select files (.txt) and then write these file names to a text file. I am thinking I am on the right track but this is not working for me and I do not know why. It creates the file list .txt but does not place the filenames into the text document.
import Tkinter, tkFileDialog
root = Tkinter.Tk()
files = tkFileDialog.askopenfilenames(parent = root, title = "Select files...", multiple =1)
SPSSList = open('list.txt', 'w')
SPSSList.write(files)
SPSSList.close()
Sorry if I am missing something obvious and I appreciate any help.
file.writetakes a string;askopenfilenamesreturns a tuple of filenames.Use
if you want to write them each on a separate line. Alternately,
is somewhat more flexible since you can choose to use a different separator (e.g.
','.join).