-
Notifications
You must be signed in to change notification settings - Fork 501
Expand file tree
/
Copy pathmoveFile.py
More file actions
27 lines (22 loc) · 795 Bytes
/
moveFile.py
File metadata and controls
27 lines (22 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import boto3
awsAccessKeyId = ""
awsSecretAccessKey = ""
bucketName = ""
directoryName = ""
s3 = boto3.resource(
"s3", aws_access_key_id=awsAccessKeyId, aws_secret_access_key=awsSecretAccessKey
)
myBucket = s3.Bucket(bucketName)
def moveFile():
try:
for objectSummary in myBucket.objects.filter(Prefix=directoryName):
s3FilePath = objectSummary.key
sourceFilename = (s3FilePath).split("/")[-1]
copySource = {"Bucket": bucketName, "Key": s3FilePath}
targetFilename = f"{destinationDirectory}/{sourceFilename}"
s3.meta.client.copy(copySource, bucketName, targetFilename)
s3.Object(bucketName, s3FilePath).delete()
except Exception as err:
print(err)
if __name__ == "__main__":
moveFile()