You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
swarms/scripts/cleanup/json_log_cleanup.py

35 lines
1.1 KiB

8 months ago
import os
import shutil
def cleanup_json_logs(name: str = None):
8 months ago
# Define the root directory and the target directory
root_dir = os.getcwd()
target_dir = os.path.join(root_dir, name)
8 months ago
# Create the target directory if it doesn't exist
if not os.path.exists(target_dir):
os.makedirs(target_dir)
# Walk through the root directory
for dirpath, dirnames, filenames in os.walk(root_dir):
for filename in filenames:
# If the file is a JSON log file, .log file or .txt file
if (
filename.endswith(".json")
or filename.endswith(".log")
# or filename.endswith(".txt")
):
8 months ago
# Construct the full file paths
file_path = os.path.join(dirpath, filename)
target_path = os.path.join(target_dir, filename)
# Move the file to the target directory
shutil.move(file_path, target_path)
print(f"All JSON, LOG and TXT files have been moved to {target_dir}")
8 months ago
# Call the function
cleanup_json_logs("artifacts_three")