0.0.3
This commit is contained in:
+7
-5
@@ -35,9 +35,10 @@ def clean_log_files(directory):
|
|||||||
file_size = os.path.getsize(file_path) # 获取文件大小
|
file_size = os.path.getsize(file_path) # 获取文件大小
|
||||||
os.remove(file_path)
|
os.remove(file_path)
|
||||||
# 记录删除操作
|
# 记录删除操作
|
||||||
with open(log_file, 'a') as f:
|
size_mb = round(file_size / (1024 * 1024), 2) # 转换为MB
|
||||||
f.write(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - Deleted: {file_path} ({file_size} bytes)\n")
|
with open(log_file, 'a', encoding='utf-8') as f:
|
||||||
print(f"Deleted: {file_path} ({file_size} bytes)")
|
f.write(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - Deleted: {file_path} ({size_mb} MB)\n")
|
||||||
|
print(f"Deleted: {file_path} ({size_mb} MB)")
|
||||||
total_size += file_size
|
total_size += file_size
|
||||||
deleted_count += 1
|
deleted_count += 1
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -45,8 +46,9 @@ def clean_log_files(directory):
|
|||||||
|
|
||||||
# 记录本次清理的总大小
|
# 记录本次清理的总大小
|
||||||
if deleted_count > 0:
|
if deleted_count > 0:
|
||||||
with open(log_file, 'a') as f:
|
total_mb = round(total_size / (1024 * 1024), 2) # 转换为MB
|
||||||
f.write(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - Total: Deleted {deleted_count} files, {total_size} bytes\n")
|
with open(log_file, 'a', encoding='utf-8') as f:
|
||||||
|
f.write(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - Total: Deleted {deleted_count} files, {total_mb} MB\n")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if os.path.isdir(TARGET_DIR):
|
if os.path.isdir(TARGET_DIR):
|
||||||
|
|||||||
Reference in New Issue
Block a user