How to create an empty folder on Google Storage with Google API? (Assume that /
is path separator.)
Google Cloud Storage does not have folders or subdirectories. However, there is some support for emulating them. gsutil's How Subdirectories Work is a good read for some background.
Google Cloud Storage objects are a flat namespace, but many tools, including gsutil and the Google Cloud Storage UI, create an illusion of a hierarchical file tree.
There are two widely used conventions for creating the illusion of an empty subdirectory:
(recommended) Create an object that ends in a trailing slash. For example, to create a subdirectory called foo
at the root of a bucket, you would create an empty object (size 0) called foo/
.
(legacy) Create an object with _$folder$
appended to the name. For example, to create a subdirectory called foo
at the root of a bucket, you would create an empty object (size 0) called foo_$folder$
.
Note that most tools and utilities are using method 1 now. Method 2 is less frequently used.