<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Unable to list files in shared Dropbox folder using Python and the Dropbox API in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Unable-to-list-files-in-shared-Dropbox-folder-using-Python-and/m-p/667603#M30206</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I got an error on line 27 of my code:&lt;/P&gt;&lt;P&gt;---&amp;gt; 27 directories = os.listdir(folder_path)&lt;/P&gt;&lt;P&gt;Do you have any alternative code suggestions? Also, if possible, could you show me where to insert the code changes in my base?&lt;/P&gt;&lt;P&gt;FYI I run the script in Google Colab. Thanks!"&lt;/P&gt;</description>
    <pubDate>Mon, 13 Mar 2023 20:44:54 GMT</pubDate>
    <dc:creator>muratowski</dc:creator>
    <dc:date>2023-03-13T20:44:54Z</dc:date>
    <item>
      <title>Unable to list files in shared Dropbox folder using Python and the Dropbox API</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Unable-to-list-files-in-shared-Dropbox-folder-using-Python-and/m-p/667577#M30204</link>
      <description>I am trying to use Python and the Dropbox API to list the files in a shared Dropbox folder.&lt;BR /&gt;&lt;BR /&gt;Here is my source code:&lt;BR /&gt;&lt;BR /&gt;"""&lt;BR /&gt;import dropbox&lt;BR /&gt;import os&lt;BR /&gt;&lt;BR /&gt;# Replace "ACCESS_TOKEN" with your Dropbox access token&lt;BR /&gt;ACCESS_TOKEN = "MY_ACCESS_TOKEN"&lt;BR /&gt;&lt;BR /&gt;# Replace "&lt;A href="https://www.dropbox.com/sh/" target="_blank"&gt;https://www.dropbox.com/sh/&lt;/A&gt;..." with the shared link to the folder containing the directories you want to rename&lt;BR /&gt;shared_link_url = "d"&lt;BR /&gt;&lt;BR /&gt;# Initialize the Dropbox API client&lt;BR /&gt;dbx = dropbox.Dropbox(ACCESS_TOKEN)&lt;BR /&gt;&lt;BR /&gt;# Get the SharedLinkMetadata for the shared link&lt;BR /&gt;shared_link_metadata = dbx.sharing_get_shared_link_metadata(url=shared_link_url)&lt;BR /&gt;&lt;BR /&gt;# Create a SharedLink object from the SharedLinkMetadata&lt;BR /&gt;shared_link = dropbox.files.SharedLink(url=shared_link_metadata.url)&lt;BR /&gt;&lt;BR /&gt;# Get the list of files in the shared link&lt;BR /&gt;shared_link_metadata = dbx.files_list_folder(path="", shared_link=shared_link)&lt;BR /&gt;entries = shared_link_metadata.entries&lt;BR /&gt;&lt;BR /&gt;# Get the path of the folder containing the directories to be renamed&lt;BR /&gt;folder_path = entries[-1].path_display&lt;BR /&gt;&lt;BR /&gt;# Get a list of the directories in the folder&lt;BR /&gt;directories = os.listdir(folder_path)&lt;BR /&gt;&lt;BR /&gt;# Loop through each directory and rename it&lt;BR /&gt;for directory in directories:&lt;BR /&gt;try:&lt;BR /&gt;if os.path.isdir(os.path.join(folder_path, directory)):&lt;BR /&gt;# Check if the directory name can be split into three parts using a dot as a separator&lt;BR /&gt;if len(directory.split(".")) != 3:&lt;BR /&gt;print(f"Skipping {directory} - not in day.month.year format")&lt;BR /&gt;continue&lt;BR /&gt;&lt;BR /&gt;# Split the directory name into day, month, and year components&lt;BR /&gt;day, month, year = directory.split(".")&lt;BR /&gt;&lt;BR /&gt;# Combine the components into the new directory name format&lt;BR /&gt;new_directory_name = f"{year}-{month}-{day}"&lt;BR /&gt;&lt;BR /&gt;# Get the current path and the new path for the directory&lt;BR /&gt;current_path = os.path.join(folder_path, directory)&lt;BR /&gt;new_path = os.path.join(folder_path, new_directory_name)&lt;BR /&gt;&lt;BR /&gt;# Rename the directory locally&lt;BR /&gt;os.rename(current_path, new_path)&lt;BR /&gt;&lt;BR /&gt;# Upload the renamed directory to Dropbox&lt;BR /&gt;with open(new_path, "rb") as f:&lt;BR /&gt;dbx.files_upload(f.read(), f"/{new_directory_name}", mode=dropbox.files.WriteMode("overwrite"))&lt;BR /&gt;&lt;BR /&gt;except FileNotFoundError:&lt;BR /&gt;print(f"Directory {directory} not found.")&lt;BR /&gt;continue&lt;BR /&gt;"""&lt;BR /&gt;&lt;BR /&gt;I'm trying to rename directories with dates in specific paths in my Dropbox account using Python and the Dropbox API. However, I keep getting the same error message, 'FileNotFoundError: [Errno 2] No such file or directory,' even though I have granted all necessary permissions in both.</description>
      <pubDate>Mon, 13 Mar 2023 19:41:10 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Unable-to-list-files-in-shared-Dropbox-folder-using-Python-and/m-p/667577#M30204</guid>
      <dc:creator>muratowski</dc:creator>
      <dc:date>2023-03-13T19:41:10Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to list files in shared Dropbox folder using Python and the Dropbox API</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Unable-to-list-files-in-shared-Dropbox-folder-using-Python-and/m-p/667600#M30205</link>
      <description>&lt;P&gt;[Cross-linking for reference: &lt;A href="https://stackoverflow.com/questions/75725830/unable-to-list-files-in-shared-dropbox-folder-using-python-and-the-dropbox-api" target="_blank"&gt;https://stackoverflow.com/questions/75725830/unable-to-list-files-in-shared-dropbox-folder-using-python-and-the-dropbox-api&lt;/A&gt; ]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which line is resulting in that error? It looks like that error is probably referring to a local filesystem operation, not a Dropbox API call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, while it's probably not related to this particular error, there are some other things to note for the Dropbox API methods:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You've implemented &lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox_client.Dropbox.files_list_folder" target="_blank"&gt;files_list_folder&lt;/A&gt; but not &lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox_client.Dropbox.files_list_folder_continue" target="_blank"&gt;files_list_folder_continue&lt;/A&gt;. You're not guaranteed to get all of the entries returned in one call to &lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox_client.Dropbox.files_list_folder" target="_blank"&gt;files_list_folder&lt;/A&gt; so make sure you've implemented &lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox_client.Dropbox.files_list_folder_continue" target="_blank"&gt;files_list_folder_continue&lt;/A&gt; as well. Check out the linked documentation for more information.&lt;/LI&gt;
&lt;LI&gt;You're relying on 'entries[-1]' to find a folder entry, but note that the position of specific entries in any particular page of results in not guaranteed.&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Mon, 13 Mar 2023 20:22:00 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Unable-to-list-files-in-shared-Dropbox-folder-using-Python-and/m-p/667600#M30205</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2023-03-13T20:22:00Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to list files in shared Dropbox folder using Python and the Dropbox API</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Unable-to-list-files-in-shared-Dropbox-folder-using-Python-and/m-p/667603#M30206</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I got an error on line 27 of my code:&lt;/P&gt;&lt;P&gt;---&amp;gt; 27 directories = os.listdir(folder_path)&lt;/P&gt;&lt;P&gt;Do you have any alternative code suggestions? Also, if possible, could you show me where to insert the code changes in my base?&lt;/P&gt;&lt;P&gt;FYI I run the script in Google Colab. Thanks!"&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 20:44:54 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Unable-to-list-files-in-shared-Dropbox-folder-using-Python-and/m-p/667603#M30206</guid>
      <dc:creator>muratowski</dc:creator>
      <dc:date>2023-03-13T20:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to list files in shared Dropbox folder using Python and the Dropbox API</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Unable-to-list-files-in-shared-Dropbox-folder-using-Python-and/m-p/667610#M30207</link>
      <description>&lt;P&gt;The &lt;A href="https://docs.python.org/3/library/os.html#os.listdir" target="_blank"&gt;os.listdir method&lt;/A&gt; is a Python method for listing the contents of a particular folder on the local filesystem at the specific path. It accesses the files and folders on the device and a&amp;nbsp;FileNotFoundError error from it would indicate that there is nothing at the local path you specified, in this case using the value in the&amp;nbsp;folder_path variable. The method does not call the Dropbox API and is not made by Dropbox though, so Dropbox can't offer support for that in particular.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I see you are getting the folder_path value from the files_list_folder results. That would only work with os.listdir if the path to the relevant folder on your local machine happened to match the path to it inside your Dropbox account.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't have full context on your project or the requirements and constraints you're working under of course, so I can't tell you exactly what code you should write. It may be helpful to step through with a debugger to see what each line is doing and update your code accordingly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It may also be worth mentioning that if you ultimately want to move or rename files or folders in Dropbox, you can do so directly using the Dropbox API (whether or not you have your Dropbox folder synced to your computer locally), without interacting with the local filesystem. To move or rename a file or folder using the Dropbox API via the Dropbox Python SDK, you would use &lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox_client.Dropbox.files_move_v2" target="_blank"&gt;files_move_v2&lt;/A&gt;. And as noted earlier, you can use &lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox_client.Dropbox.files_list_folder" target="_blank" rel="nofollow noopener noreferrer"&gt;files_list_folder&lt;/A&gt; and &lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox_client.Dropbox.files_list_folder_continue" target="_blank" rel="nofollow noopener noreferrer"&gt;files_list_folder_continue&lt;/A&gt; to list the contents of a folder (even without a shared link, if the content is in your connected Dropbox account). You may also want to check out the &lt;A href="https://www.dropbox.com/developers/reference/getting-started" target="_blank"&gt;Getting Started&lt;/A&gt; and &lt;A href="https://developers.dropbox.com/dbx-file-access-guide" target="_blank"&gt;File Access&lt;/A&gt; guides.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 21:03:32 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Unable-to-list-files-in-shared-Dropbox-folder-using-Python-and/m-p/667610#M30207</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2023-03-13T21:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to list files in shared Dropbox folder using Python and the Dropbox API</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Unable-to-list-files-in-shared-Dropbox-folder-using-Python-and/m-p/667626#M30208</link>
      <description>&lt;P&gt;Thank you for the explanation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I would like a Python script that can rename all the subdirectories within a specific main directory in my Dropbox account. The subdirectory names are currently in the format 'dd.mm.yyyy', but I would like them to be changed to the format 'yyyy-mm-dd'. I would like to be able to run this script by providing a link to the specific folder in my Dropbox account. If you have any simpler code snippet for it, I'd be happy to see that.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 21:48:37 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Unable-to-list-files-in-shared-Dropbox-folder-using-Python-and/m-p/667626#M30208</guid>
      <dc:creator>muratowski</dc:creator>
      <dc:date>2023-03-13T21:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to list files in shared Dropbox folder using Python and the Dropbox API</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Unable-to-list-files-in-shared-Dropbox-folder-using-Python-and/m-p/667742#M30210</link>
      <description>&lt;P&gt;Ok I changed my codebase a little bit and now it works perfectly!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank your for your efforts.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 09:56:19 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Unable-to-list-files-in-shared-Dropbox-folder-using-Python-and/m-p/667742#M30210</guid>
      <dc:creator>muratowski</dc:creator>
      <dc:date>2023-03-14T09:56:19Z</dc:date>
    </item>
  </channel>
</rss>

