How to List Files of a Mega. Nz Folder Using Python 3.9.1?

I only found this:

m = mega.login('email', 'password')

files = m.get_files()
extracted = []
for file in files:
   extracted.append(files[file]['a']['n'])

it returns all of the files and folders:

['Cloud Drive', 'Inbox', 'Rubbish Bin', 'Welcome to MEGA.pdf', 'FolderN1', 'balloon.png', 'FolderN1/subfolder/balloon.png', 'subfolder', etc. ]
2

1 Answer

if (files[x]['t'] == 0) it is file.

files = m.get_files()
extracted = []
for x in files:
  if files[x]['t'] == 0:
     extracted.append(files[x]['a']['n'])

example results:

['video.zip', 'film.mkv', 'legal_data.zip', 'tools.py', 'upload.py', 'learn.pdf']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest