コメント

6件のコメント

  • jcleblanc

    Hi ,

     

    You'll want the List items in folder endpoint, that should give you the information that you're looking for.

     

    - Jon

    0
    コメントアクション パーマリンク
  • downunder

    It shows files/folders in *current* directory only. I need a recursive list.

    0
    コメントアクション パーマリンク
  • Jason Friedman

    The code below works for me. Here's my folder/file structure:

    • Folder1
    • * file1.1
    • * file1.2
    • Folder2
    • * file2.1
    • * file2.2
    • file1
    • file2

    import os
    import boxsdk

    auth = boxsdk.OAuth2(
    client_id=config['boxAppSettings']['clientID'],
    client_secret='',
    access_token=access_token
    )

    client = boxsdk.Client(auth)

    def get_recursive(dir_list):
    for item in dir_list[-1].get_items():
    file_info = item.get()
    if file_info.type == "folder":
    dir_list.append(item)
    yield from get_recursive(dir_list)
    else:
    yield "/".join([x.get().name for x in dir_list]) + "/" + item.get().name
    dir_list.pop()

    print(os.linesep.join(list(get_recursive([client.folder('0')]))))

    Which for my structure prints:

    All Files/Folder1/file1.1
    All Files/Folder1/file1.2
    All Files/Folder2/file2.1
    All Files/Folder2/file2.2
    All Files/file1
    All Files/file2

    1
    コメントアクション パーマリンク
  • sushant prajapati

    Hi I am new to box apis. Just one question to @Jason Friedman  does it work for very large numbers of folders?

    0
    コメントアクション パーマリンク
  • Jason Friedman

    Yes ... but, the token times out after 60 minutes. You will need to add to my code try/except blocks to identify that situation and get a new token.

    0
    コメントアクション パーマリンク
  • Jason Friedman

    Indeed that is probably true. I no longer have my test setup but I believe something like this would likely fix the bug you have identified:

    import os
    import boxsdk

    auth = boxsdk.OAuth2(
    client_id=config['boxAppSettings']['clientID'],
    client_secret='',
    access_token=access_token
    )

    client = boxsdk.Client(auth)

    def get_recursive(dir_list):
    for item in dir_list[-1].get_items():
    file_info = item.get()
    yield "/".join([x.get().name for x in dir_list]) + "/" + item.get().name
    if file_info.type == "folder":
    dir_list.append(item)
    yield from get_recursive(dir_list)
    dir_list.pop()

    print(os.linesep.join(list(get_recursive([client.folder('0')]))))

    1
    コメントアクション パーマリンク

サインインしてコメントを残してください。