L
Laura McCord
This is probably a very basic question but I started learning python. I
am almost done writing my delete directory script but I am at a stand
still right now.
I want to delete folders in my "/var/www/html/da" directory that are
over 1 day old.
But, when I find the folder a simple rmdir() command does not work
because the directory is not empty. What else do I need to do to delete
a directory that contains content?
Here is the code:
dir = "/var/www/html/da"
currentTime = int(time.time())
print currentTime
dirfiles = os.listdir(dir)
print dirfiles
for name in dirfiles:
dirpath = os.path.join(dir, name)
mod_time = os.path.getmtime(dirpath)
timeDiff = currentTime - mod_time
if timeDiff > maxOld:
print dirpath
Thanks,
Laura
am almost done writing my delete directory script but I am at a stand
still right now.
I want to delete folders in my "/var/www/html/da" directory that are
over 1 day old.
But, when I find the folder a simple rmdir() command does not work
because the directory is not empty. What else do I need to do to delete
a directory that contains content?
Here is the code:
dir = "/var/www/html/da"
currentTime = int(time.time())
print currentTime
dirfiles = os.listdir(dir)
print dirfiles
for name in dirfiles:
dirpath = os.path.join(dir, name)
mod_time = os.path.getmtime(dirpath)
timeDiff = currentTime - mod_time
if timeDiff > maxOld:
print dirpath
Thanks,
Laura