Search code examples
google-cloud-platformbucket

Folder name with date on GCP


I want to create a folder in GCP bucket with date as suffix: I am trying this

gsutil mkdir gs://bucket_name/raw/data_"$(date +"%m-%d-%y")"

I also tried this:

dt="$(date +"%m-%d-%y")"
mkdir data_$dt
gsutil cp -r data_$dt gs://bucket_name/raw/

But in this getting error :

CommandException: No URLs matched

is there any other way?


Solution

  • Folders doesn't exist in Cloud Storage. The folder representation on the console is simply a human representation.

    All the blobs are stored at the root of the bucket. The file name contain the path (that you name folder) and the effective name. Thus, if you add a file with a path, you see directories. If you remove it, all the directories disappeared.

    Because of this, you can't filter on a file pattern, only on the path prefix.

    So, the solution if you want to do this is to create a placeholder file

    dt="$(date +"%m-%d-%y")"
    mkdir data_$dt
    touch data_$dt/placeholder
    gsutil cp -r data_$dt gs://bucket_name/raw/