Created
July 14, 2022 22:16
-
-
Save rationalism/145ce1349d4e74542c2ae90dd72fde8a to your computer and use it in GitHub Desktop.
File moving code
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
def move_files(directory): | |
"""This function duplicates every JPEG and moves the copies | |
to a folder called 'bar'.""" | |
import os | |
import shutil | |
import glob | |
import time | |
import random | |
import string | |
import sys | |
import re | |
import argparse | |
# Create a parser | |
parser = argparse.ArgumentParser(description='Move files to a new directory') | |
# Add arguments | |
parser.add_argument('-d', '--directory', type=str, help='The directory to move files to') | |
# Execute the parser | |
args = parser.parse_args() | |
# Get the directory | |
directory = args.directory | |
# Check if the directory exists | |
if not os.path.exists(directory): | |
print('The directory does not exist') | |
sys.exit() | |
# Get the files | |
files = glob.glob('*.jpg') | |
# Move the files | |
for file in files: | |
shutil.copy(file, directory) | |
os.remove(file) | |
print('Moved ' + file) | |
time.sleep(random.randint(1, 3)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment