Last active
May 4, 2021 15:50
-
-
Save micahmelling/adb36796559e3bdd8cbc5868deef9a74 to your computer and use it in GitHub Desktop.
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 | |
from tqdm import tqdm | |
def upload_directory_to_s3(local_directory, bucket): | |
""" | |
Uploads an entire directory to S3. | |
:param local_directory: name of the local directory | |
:param bucket: name of the S3 bucket | |
""" | |
print(f'uploading all files in {local_directory}') | |
directory_walk = os.walk(local_directory) | |
for directory_path, directory_name, file_names in directory_walk: | |
if directory_path != os.path.join(local_directory): | |
sub_dir = os.path.basename(directory_path) | |
for file in tqdm(file_names): | |
aws.upload_file_to_s3(file_name=os.path.join(local_directory, sub_dir, file), bucket=bucket) | |
else: | |
for file in tqdm(file_names): | |
aws.upload_file_to_s3(file_name=os.path.join(local_directory, file), bucket=bucket) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment