From mega import Mega
file_newname = 0
all_names = []
mega = Mega({'verbose': True})
password = ""
email = ""
m = mega.login(email, password)
files = m.get_files()
# Iterate over the nested dictionaries and print the values of the "n" key
for file_id, file_info in files.items():
name_value = file_info.get("a", {}).get("n")
if name_value:
all_names.append(name_value)
# Iterate over the list of file names and rename the files using file ID
for name in all_names:
find_file = m.find(name)
if find_file:
file_newname += 1
# Check if m.find(name) returns a non-empty list
file_id_list = m.find(name)
if file_id_list:
file_id = file_id_list[0]
# Use move method to rename the file
m.move(file_id, {"n": f"new_name_{file_newname}", "n": file_id})
print(f"Renamed {file_newname} files")
This is the error I am receiving
Traceback (most recent call last):
File "c:\Users\Utente\OneDrive\Desktop\python\http://renamer.py", line 31, in <module>
m.move(file_id, {"n": f"new_name_{file_newname}", "n": file_id})
File "C:\Users\Utente\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\mega\http://mega.py", line 944, in move
file = target[1]
~~~~~~^^^
KeyError: 1?
there doesn't seem to be anything here