I am currently working on my code. I basically want my code to loop through a dictionary and see if this raw_input is the same as a key in the dictionary. It does not loop through the dictionary though, and I do not know why. Here is my looping code:
for filename in files:
if filename.lower() == deletename.lower():
break
del files[filename]
print "\nFile Removed"
print "--------------------------------------------"
startup()
Then below is my full code:
import datetime
import time
files = {}
# g = open('files.txt', 'r')
# g.read(str(files))
# g.close()
def startup():
print "\n ------------------- "
print " FILE SYSTEM MANAGER "
print " ------------------- "
print "\n What would you like to do with your files?"
print " To make a new file type in: NEW"
print " To edit a current file type in: EDIT"
print " To delete a current file type in: DELETE"
print " To view all current files type in: ALL"
print " To search a specific file type in: SEARCH"
chooser = raw_input("\n Please enter NEW, EDIT, DELETE, ALL, or SEARCH: ")
if chooser.lower() == "new":
newfile()
elif chooser.lower() == "edit":
editfiles()
elif chooser.lower() == "delete":
deletefiles()
elif chooser.lower() == "all":
allfiles()
elif chooser.lower() == "search":
searchfiles()
else:
startup()
def newfile():
filename = ""
filetext = ""
while filename == "":
print "--------------------------------------------"
filename = raw_input("\n Please input your new files name: ")
while filetext == "":
filetext = raw_input("\n Please input the text for your new file: ")
filedate = datetime.date.today()
files[filename] = {filedate:filetext}
# f = open ('files.txt', 'w')
# f.write(str(files))
# f.close()
print "\n File Added"
print "\n--------------------------------------------"
startup()
def editfiles():
pass
def deletefiles():
print "--------------------------------------------"
print " To delete a file type in: DELETE"
print " To view all current files type in: ALLFILES"
print " To cancel type in: CANCEL"
wheretogo = raw_input("\n Please enter DELETE, ALLFILES, or CANCEL: ")
if wheretogo.lower() == "delete":
print "\n To delete a file type in its name"
print " To cancel type in: CANCEL"
deletename = raw_input("\n Please type in the file's name or CANCEL: ")
if deletename.lower() == "cancel":
startup()
else:
for filename in files:
if filename.lower() == deletename.lower():
break
del files[filename]
print "\nFile Removed"
print "--------------------------------------------"
startup()
else:
pass
print "\nFile not found!"
deletefiles()
elif wheretogo.lower() == "allfiles":
print "\n--------------------------------------------"
for filename in files:
print "File Name: " + str(filename)
print "--------------------------------------------"
print "\n To delete a file type in: DELETE"
print " To cancel type in: CANCEL"
wheretogo = raw_input("\n Please enter DELETE or CANCEL: ")
if wheretogo.lower() == "delete":
pass
elif wheretogo.lower() == "cancel":
startup()
else:
startup()
elif wheretogo.lower() == "cancel":
startup()
else:
startup()
def allfiles():
filetexttotal = ""
for filename in files:
print "\n--------------------------------------------"
print "File Name: " + str(filename)
for filedate in files[filename]:
print "File Date: " + str(filedate)
for filetext in files[filename][filedate]:
filetexttotal = filetexttotal + str(filetext)
print "File Contents: " + str(filetexttotal)
filetexttotal = ""
print "--------------------------------------------"
startup()
def searchfiles():
pass
startup()