EvilZone
Programming and Scripting => Scripting Languages => Topic started by: pyte on May 24, 2013, 07:35:30 AM
-
Hi guyz,
I have been trying to write a script to search for files with multiple extensions (.txt, .odt, .bat, .Fvl etc )in a directory , i tried using (path/*.*) but it still doesn't work for me.
here is the script i have written .Kindly go through it and point out any errors or mistakes in the script suggesting how to do it better.
thanks in advance.
Regards ,
Pyte
!#usr/bin/python
import os, datetime
Path = "/home/pytbyte/Documents/kim.doc" # this works fine but ("/home/pytbyte/Documents/*.*") doesn't
last_modified = datetime.datetime.fromtimestamp(os.path.getmtime(Path))
print "last_modified:", last_modified
if datetime.datetime.now() - last_modified > datetime.timedelta(hours=50):
print "too old! "
-
http://stackoverflow.com/questions/3964681 (http://stackoverflow.com/questions/3964681)
You could loop over the answer in the above link for each extension.
-
was there earlier and that does work for the specified (extension .txt) . in my case i want to handle all extensions at a go since il be working with multiple in a directory. on the other hand i have noted the os.walk() which would be better for my case.
Thanx.
-
I used something similar recently also with os.walk()
Ill post a snipper as soon as I have the code nearby.
-
thank. proxx
by the way i did get the right way to search for all extensions:
this is how..
import os
rootPath = '/some/path'
pattern = "*.*"
for root, dirs, files in os.walk(rootPath):
for filename in fnmatch.filter(files, pattern):
print filename
Staff note: you don't want to double-post again.