0

I'm trying to rename my file toto.html by removing its extension using gsutils. My folder/files are organized this way:

toto     ----|
             |
             |--file1.html
             |
             |--file2.txt
             |
             |-- ...
             |
toto.html

So I used the command :

gsutil mv gs://my_bucket/toto.html  gs://my_bucket/toto

the problem is by doing so, the file is moved inside the folder that has the same name as the directory. ( which is normal )

How can I rename my file without having this issue?

thanks in advance.

zoey3
  • 170
  • 1
  • 2
  • 14
  • are you trying to convert file to directory ? – Gaurang Shah Mar 16 '22 at 15:42
  • No, i’m trying to remove the extension of my file toto.html and the file gets moved inside the directory – zoey3 Mar 16 '22 at 15:44
  • If you plan to use gsutil or the Google Cloud Console GUI in the future, **do not do this**. They have special behavior to **emulate** directories, which do not exist in Cloud Storage. Otherwise, you will need to use an API/SDK to rename the object. – John Hanley Mar 16 '22 at 16:30

1 Answers1

2

Let me explain briefly about how directories work on Google Cloud Storage, as detailed in the documentation:

Cloud Storage operates with a flat namespace, which means that folders don't actually exist within Cloud Storage. If you create an object named folder1/file.txt in the bucket your-bucket, the path to the object is your-bucket/folder1/file.txt, but there is no folder named folder1; instead, the string folder1 is part of the object's name.

So when you perform the move command gsutil mv gs://my_bucket/toto.html gs://my_bucket/toto, gsutil interprets it like you would like to move the file inside the folder named toto as there is no way to differentiate between the file and the folder.

What you could do to achieve the task is move the file inside a folder first to change its name and then get it back to root:

gsutil mv gs://my_bucket/toto.html  gs://my_bucket/toto/toto
gsutil mv gs://my_bucket/toto/toto  gs://my_bucket/
Emmanuel
  • 1,436
  • 1
  • 11
  • 17