I am trying to use python's "glob" to grab various files using a wildcard AND NOT the path in which the files came.
In this situation, I am trying to capture all files that begin with the name file_
within a directory. Though there can be situations in the future where I need to grab files base on their file extension(s) (i.e. all .csv and .log)
files from a directory.
The python string below is what I am using, which is only able to grab the FULL PATH, along with the intended file. I only want to "glob" the file itself, and NOT THE PATH
import os
import glob
import boto3
from botocore.client import Config
ACCESS_KEY_ID = 'some_key'
ACCESS_SECRET_KEY = 'some_key'
BUCKET_NAME = 'some_bucket'
s3 = boto3.client(
's3',
aws_access_key_id=ACCESS_KEY_ID,
aws_secret_access_key=ACCESS_SECRET_KEY,
config=Config(signature_version='s3v4')
)
csv_files = glob.glob('/home/user/folder1/folder2/*.csv')
#json_files = glob.glob("/home/user/folder1/h_log_*.json")
for filename in csv_files:
print("Putting %s" % filename)
s3.upload_file(filename, BUCKET_NAME, 'new_folder' + '/' + filename)
#for filename in json_files:
# print("Putting %s" % filename)
# s3.upload_file(filename, BUCKET_NAME, filename)
print("All_Finished")
####################################################
####################################################
The string I am trying to concentrate on updating from the script preferably is below:
csv_files = glob.glob('/home/user/folder1/folder2/*.csv')
An example of a file directory containing various files and file types :
Below need to grab all files that end in `.csv`
/home/user/Desktop/folder_example/
file_1.csv
file_1.csv
file_1.csv
file_1.csv
Below need to grab all files that start with `file_`
/home/user/Desktop/folder_example/
file_2.log
file_2.csv
file_2.log
file_2.csv