feat: addet datetime to merged file
This commit is contained in:
parent
671349c13c
commit
6031cd584c
1 changed files with 13 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
def merge_files(file_paths):
|
def merge_files(file_paths):
|
||||||
# Dictionary to hold file contents by extension
|
# Dictionary to hold file contents by extension
|
||||||
|
@ -12,9 +13,20 @@ def merge_files(file_paths):
|
||||||
with open(file_path, 'r') as file:
|
with open(file_path, 'r') as file:
|
||||||
files_by_extension[ext].append(file.read())
|
files_by_extension[ext].append(file.read())
|
||||||
|
|
||||||
|
# Ensure the .old directory exists
|
||||||
|
old_dir = '.old'
|
||||||
|
if not os.path.exists(old_dir):
|
||||||
|
os.makedirs(old_dir)
|
||||||
|
|
||||||
# Write merged contents to new files
|
# Write merged contents to new files
|
||||||
for ext, contents in files_by_extension.items():
|
for ext, contents in files_by_extension.items():
|
||||||
merged_file_path = f'merged{ext}'
|
current_date = datetime.now().strftime("%Y-%m-%d")
|
||||||
|
merged_file_path = f'{current_date}{ext}'
|
||||||
|
|
||||||
|
# Move existing merged file to .old directory
|
||||||
|
if os.path.exists(merged_file_path):
|
||||||
|
os.rename(merged_file_path, os.path.join(old_dir, f'{current_date}{ext}'))
|
||||||
|
|
||||||
with open(merged_file_path, 'w') as merged_file:
|
with open(merged_file_path, 'w') as merged_file:
|
||||||
for content in contents:
|
for content in contents:
|
||||||
merged_file.write(content)
|
merged_file.write(content)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue