Get only top level folders only using Python Box SDK
I am trying to run a search query in Box root folder to find folder names that contain a particular string. However I only want the folders that are 1 level below (similar to a
ls
command). However get_items()
will return folders matching the string even deeper down. For example if I search for "AA"
in the below folder structure it should only return Folder1AA
, Folder2AA
and Folder3AA
and not Folder4AA
and Folder5AA
:StartingFolder
Folder1AA
File1B
Folder4AA
Folder1C
File1D
Folder2AA
Folder5AA
File1C
Folder2B
File1D
Folder3AA
File1B
Any ideas on how to do that ?
-
Hello,
There is a search API that you can use to search for elements. You can find sample usage here: https://github.com/box/box-python-sdk/blob/main/docs/usage/search.md#search-for-content,
and more about the API: https://developer.box.com/guides/search/filtering/
You should be able to search all elements containing "AA" with this snippet
items = client.search().query(query='AA')
for item in items:
print(f'{item.id} "{item.name}"')please bear in mind that this search is index based. So if you create new file/folder it might appear in search results after index refresh which can take at minimum 10 minutes (https://developer.box.com/guides/search/indexing/#search-availability)
投稿コメントは受け付けていません。
コメント
1件のコメント