I am currently trying to use python to extract information from one file, find the data that I need then save it to another file for later use.
badgecommandlist = []
directory = "D:\Python\Badge Recovery"
for filename in os.listdir(directory): #open each file
newname = directory + "/" + filename
print(filename)
f=open(newname, "r")
lines = f.readlines() #read content of each file
f.close()
for line in lines:
if "badge give" in line or "badge share" in line or "badge take" in line or "badge leave" in line or "badge create" in line: #check if badge command is in each line
badgecommandlist.append(line)
print(badgecommandlist)
f=open("commandlist.txt", "w")
for line in badgecommandlist:
f.writelines(line)
f.close()
The data is being saved into the list (checked by the print statement) but it isn't being saved to the file "commandlist.txt"
Any ideas on why it isnt saving? It worked fine on another script that was very similar