Three days ago deletion log .py python


# Get all files
DEF File ():
for cur_dir, dirs, Files in os.walk (r '/ learn / Interface Automation / BestTest / jobs / logs'): # cur_dir (current path), dirs (directory), files ( file) all
for files in file:
abs_path = os.path.join (cur_dir, file) # get the absolute path
if int (timestamp_to_str (abs_path.split ( " _") [1] .split () [ "." 0], format = '% Y- % m-% d')) <timestamp_to_str (format = '% Y-% m-% d') - 60 * 60 * 24 * 3 or os.path.getsize (abs_path) 0 ==:
os.remove (abs_path)
the else:
Print ( "% S file is 3 days, you do not need to delete the"% file)
# three days time
def timestamp_to_str (stringtime = None, format = '% Y-% % D M- '):
# formatted time stamp is converted to
IF stringtime:
Result = time.mktime (time.strptime(stringtime,format))
return int(result)
else:
result = time.time()
return int(result)

file()


Guess you like

Origin www.cnblogs.com/wangyajuanjuan/p/11735920.html