Created
August 26, 2024 10:03
-
-
Save dominik-ba/d39e9b248b8d9e41613ef9612f90286f to your computer and use it in GitHub Desktop.
python helpfull scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import shutil | |
source_dir = os.getcwd() | |
for filename in os.listdir(source_dir): | |
try: | |
if filename[:4] == 'test': | |
file_path = os.path.join(source_dir, filename) | |
shutil.move(file_path, os.path.join(source_dir, 'test')) | |
elif filename[4] == 'd': | |
file_path = os.path.join(source_dir, filename) | |
shutil.move(file_path, os.path.join(source_dir, 'dev')) | |
elif filename[4] == 'p' and filename[5] == '2': | |
file_path = os.path.join(source_dir, filename) | |
shutil.move(file_path, os.path.join(source_dir, 'prod')) | |
except: | |
pass | |
print("Files moved successfully!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import argparse | |
source_dir = os.getcwd() | |
parser = argparse.ArgumentParser(description="provide the suffix") | |
parser.add_argument('-p', '--prefix', type=str, help='prefix') | |
args = parser.parse_args() | |
for filename in os.listdir(source_dir): | |
# Define the new filename with the prefix | |
new_filename = args.prefix + '_' + filename | |
# Define the source and destination paths | |
source_path = os.path.join(source_dir, filename) | |
destination_path = os.path.join(source_dir, new_filename) | |
# Rename the file | |
os.rename(source_path, destination_path) | |
print("Files renamed successfully!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment