I wrote this script that will show all files within a specific directory and will let the user input which file he wants to edit.
import os
path = "/home/luai/Desktop/python/test"
dirs = os.listdir( path )
print "Here is a list of all files: "
for files in dirs:
print files
filename = raw_input ("which file to update: ")
if filename in dirs:
inputFile = open(filename, 'r')
else:
print "no match found"
sys.exit()
inputFile.close()
and its working, but the thing is that I want the user to only enter a number or a letter to open the file instead of writing the whole name of the file. any ideas ?
thanks.
dictyet. Try it 1st then present an actual problem. "Any ideas?" is not a very good question. Especially since you missed any clear problem statement.