Skip to content

Commit 3bd15a9

Browse files
committed
It is possible to find a folder with a "path"
1 parent b1ada6a commit 3bd15a9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

mega/mega.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,34 @@ def _init_shared_keys(self, files, shared_keys):
199199

200200
##########################################################################
201201
# GET
202+
203+
def find_path_descriptor(self, path):
204+
"""
205+
Find descriptor of folder inside a path. i.e.: folder1/folder2/folder3
206+
Params:
207+
path, string like folder1/folder2/folder3
208+
Return:
209+
Descriptor (str) of folder3 if exists, None otherwise
210+
"""
211+
paths = path.split('/')
212+
213+
files = self.get_files()
214+
parent_desc = self.root_id
215+
found = False
216+
for foldername in paths:
217+
if foldername != '':
218+
for file in files.iteritems():
219+
if file[1]['a'] and file[1]['t'] and \
220+
file[1]['a']['n'] == foldername:
221+
if parent_desc == file[1]['p']:
222+
parent_desc = file[0]
223+
found = True
224+
if found:
225+
found = False
226+
else:
227+
return None
228+
return parent_desc
229+
202230
def find(self, filename):
203231
"""
204232
Return file object from given filename

0 commit comments

Comments
 (0)