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 "rm file" in linux.
I would like to know the equivalent function for "rm -f file". Forcefully remove a file or Forcefully unlink the file path from directory.
Also the above code is trying to purge files older than today. I have a situation where the files are not deleted as it is "write-protected" due to the ownership. But when I use "rm -f" to the same file; it is getting deleted.
I think it is better to ask a question, even though it sounds stupid to yourselves