I am trying to write a script that goes through a drive. The drive has a folder structure similar to this:
| Folder 1
+--->Folder 1.txt
+--->Folder 1.nfo
| Folder 2
+--->Folder 2.doc
+--->Folder 2.nfo
+--->Folder 2.xls
| Folder 3
+--->Folder 3.txt
+--->Folder 3.nfo
older What I am trying to do is read each of the files in the directory, then when I finish going through the directory, I want to write a log to a text file. I currently open each directory and file using the following:
logfile = open("log.txt")
for path, subdirs, files in os.walk(directory):
txtfile = 0
docfile = 0
xlsfile = 0
nfofile = 0
for name in files:
file = os.path.join(path, name)
if file.endswith('.txt'):
txtfile = 1
elif file.endswith('.doc'):
docfile = 1
elif file.endswith('.xls'):
xlsfile = 1
elif file.endswith('.nfo'):
nfofile = 1
# if all files in a specific directory (Folder 1, Folder 2, etc) have been read, write line to log.txt
I am just not sure how to check the last file. The log will be used to see which files are missing from the directory. Any help on this would be greatly appreciated!