I have my code as follows:
#!/usr/bin/env python import time, glob, os, sys from datetime import date, timedelta try: dpath = sys.argv[1]+"/" except: print "usage: " + sys.argv[0] +" <dir_path_to_purge_files>" sys.exit(1) print dpath day_minus_mtime = time.mktime(date.today().timetuple()) g = glob.glob(dpath+"*") for f in g: try: if day_minus_mtime > os.path.getmtime(f): os.remove(f) print "Removed: "+f except OSError, e: print "Not able to Remove: "+f , e
I believe that os.remove (file) is equivalent to the "rm file" in Linux.
I would like to know the equivalent function for "rm -f file". Strongly delete the file or force cancel the path to the file from the directory.
In addition, the above code tries to clear files older than today. I have a situation where files are not deleted, as they are "write protected" due to ownership. But when I use "rm -f" in the same file; he is removed.
I think it's better to ask a question, although that sounds silly to myself.
source share