How would you scan a dir for a text file and read the text file by date modified, print it to screen having the script scan the directory every 5 seconds for a newer file creadted and prints it. Is it possible that you can help me i'm stuck and i need this real bad and i've already got the scan dir for file and print but it does not print the files by date modidfied.
import os,sys
os.chdir(raw_input('dir_path: ') )
contents=os.listdir('.') #contents of the current directory
files =[]
directory=[]
Time = time.ctime(os.path.getmtime(contents))
for i in contents:
if os.path.isfile(i) == True :
files.append(i)
elif os.path.isdir(i) == True :
directory.append(i)
#printing contents
choice = ""
for j in files:
while choice != "quit":
choice = raw_input("Dou you want to print file %s (y/n): "%j)
if choice == 'y':
print "**************************"
print "Printing Files %s" %j
print "**************************"
fileobj = open(j,'r')
contents = fileobj.readlines()
for k in contents:
sys.stderr.write(k)
else:
pass
what i wanted is instead of my code asking if it wants to print i need it to print the files if modified by the current time meaning if it read a file that was just placed in the directory and a new one comes in it will read the new file without prompting me. the error it's giving me is coercing to unicode: need string or buffer, list found.