7-26 2,989 views
#!/usr/bin/python
import os
import sys
files_list = []
def print_files(path):
lsdir = os.listdir(path)
dirs = [i for i in lsdir if os.path.isdir(os.path.join(path, i))]
if dirs:
for i in dirs:
print_files(os.path.join(path, i))
files = [i for i in lsdir if os.path.isfile(os.path.join(path,i))]
for f in files:
files_list.append(os.path.join(path, f))
#print(os.path.join(path, f))
return files_list
def file_extension(path):
return os.path.splitext(path)[1]
def clear_log(file):
file_ext = file_extension(file)
#print(file_ext)
if '.log' in file_ext:
modify_text(file)
return
def modify_text(log_file):
os.remove(log_file)
#with open(log_file, 'w'):
#pass
files = print_files('/apps/')
for file in files:
if os.path.isfile(file):
clear_log(file)