From 3bd15a9413194651869883887f47b836558a84b1 Mon Sep 17 00:00:00 2001 From: asanchez Date: Sat, 9 Nov 2013 18:37:32 +0100 Subject: [PATCH] It is possible to find a folder with a "path" --- mega/mega.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/mega/mega.py b/mega/mega.py index 1746cf0..fa473e9 100644 --- a/mega/mega.py +++ b/mega/mega.py @@ -199,6 +199,34 @@ class Mega(object): ########################################################################## # GET + + def find_path_descriptor(self, path): + """ + Find descriptor of folder inside a path. i.e.: folder1/folder2/folder3 + Params: + path, string like folder1/folder2/folder3 + Return: + Descriptor (str) of folder3 if exists, None otherwise + """ + paths = path.split('/') + + files = self.get_files() + parent_desc = self.root_id + found = False + for foldername in paths: + if foldername != '': + for file in files.iteritems(): + if file[1]['a'] and file[1]['t'] and \ + file[1]['a']['n'] == foldername: + if parent_desc == file[1]['p']: + parent_desc = file[0] + found = True + if found: + found = False + else: + return None + return parent_desc + def find(self, filename): """ Return file object from given filename