File Modifiaction And Manipulation
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
Solution 1:
Repeating actions on a timer
You can repeat an action every five seconds by combining an infinite loop with the time.sleep()
function, like so:
import timewhile True:
time.sleep(5) # wait five seconds
print (time.time()) # print the time
Remember to have some kind of break
condition in here if you need it, otherwise the loop will run forever.
"TypeError: coercing to Unicode: need string or buffer, list found"
Your problem is in the line
Time = time.ctime(os.path.getmtime(contents))
You have provided a list of filenames. The os.path.getmtime
function expects one filename at a time. The error message is telling you that it has no idea how to convert a list of filenames into a filename.
Post a Comment for "File Modifiaction And Manipulation"