Problem with move method in Google Drive service

What I’m trying to do: I’m trying to move a file on my Google drive to another folder.

What I’ve tried and what’s not working: I tried to use the file.move(new_folder) method as suggested in the documentation, but it throws me a KeyError: anvil_LazyMedia (despite actually moving the file)

Hi @coro.uni.sb18,

Welcome to the forum! Can you post the traceback of the error, and possibly a bit of sample code, to illustrate what’s gone wrong? (The absolute ideal would be to have a cloneable app that demonstrates the problem, but stack traces and code samples help!)

Here is some stack code and a traceback of the error. I would rather not send a clonable app because the code is written half in Italian and half in English :sweat_smile:
Basically, I have a drive folder with some files in it, including a .txt file with the same name of the folder. What I would like to do is to rename the folder and substitute the .txt file with another one. As it seems to me that there isn’t a method to rename a folder, I’m trying to create a new folder and move all the files in the old one into the new one.
Code:

old_title = self.label_old_name.text
new_name = self.label_new_name.text
folder = app_files.app.get(old_title)
old_file = folder.get(old_title+".txt")
old_file.delete()
new_file= folder.create_file(new_title+".txt",self.editor.text)
new_folder = app_files.app.create_folder(new_title)
for file in old_folder.files:
  file.move(new_folder)
old_folder.delete()

Error traceback:

KeyError: anvil_LazyMedia
at anvil-services/anvil/google/drive.py:139
called from anvil-services/anvil/google/drive.py:83
called from anvil-services/anvil/google/drive.py:121
called from modify, line 71

line 71 here, is the instruction into the for loop.
As I said, I manage to move the first file into the new folder, but then it throws me that error.
Thank you in advance for your help.

I have the same issue, when I get file object through
for f in folder_obj.files:
f.move(traget_folder)
or
for f in folder_obj…list_files():
f.move(traget_folder)
I get KeyError: anvil_LazyMedia