Reputation: 311
I have files inside a Google Cloud Storage bucket, I want to copy all the files from the bucket as received and create a copy of all those files inside a folder in the same bucket. (I found solution to copy to a bucket, but how to copy to a FOLDER inside a bucket?)
destination = storage_client.bucket('source-bucket-name')
#here my source & destination bucket is same
Is there a way to pass the folder name along with the bucket name?
Upvotes: 0
Views: 708
Reputation: 83103
Actually Google Cloud Storage does not have genuine "folders". In the Cloud Storage console, the files in your bucket are presented in a hierarchical tree of folders (just like the file system on your local hard disk) but this is just a way of presenting the files: there aren't genuine folders/directories in a bucket. The Cloud Storage console just uses the different parts of the file paths to "simulate" a folder structure, by using the "/" delimiter character.
This doc on Cloud Storage and gsutil explains and illustrates very well this "illusion of a hierarchical file tree".
So, in other words, it's up to you to use a file name (or file path) that is composed by the "folder/directory" name, then the "/" delimiter character and finally the file name. E.g.: fileName = "summer1970/pic1234.jpg"
. As clarified in the comments below, the illusion of a hierarchical file tree is created via the files naming not via the bucket naming.
Upvotes: 3