Need to see if your shared folder is taking up space on your dropbox 👨‍💻? Find out how to check here.

Forum Discussion

George K.23's avatar
George K.23
New member | Level 2
10 years ago

Python files_search() returns incorrect filenames

Hi everyone,

I'm using the files_search() function in a Python script to look at the names of files in my app's folder and based on those names, the script will perform certain functions. The script also changes the names of some files using files_move(). I've noticed that when I use files_move() to change filenames, files_search() will sometimes return incorrect results. Here's the sort of thing I'm doing:

- Have a file called 'printmessage=1' in Dropbox (no file extension)

- Use files_search() from the Python API in a loop (repeats every 10 seconds) to look for a file with 'printmessage' in its name, and extract the number after the '=' sign.

- If the number after the '=' is 1, print a message with Python and then use files_move() to change it back to 0.

- Repeat

Sometimes, after files_move() has changed the filename back to 'printmessage=0', files_search() still thinks it is 'printmessage=1'. I have checked in Dropbox and the filename is definitely 'printmessage=0'.

I'm not sure what the root of this issue could be - is there any reason why files_search() might not reflect the true contents of my Dropbox folder? Where is it getting its information from when it returns incorrect filenames?

Thanks for the help :)

2 Replies

Replies have been turned off for this discussion
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    10 years ago

    Hi George, yes, recent changes may not immediately be reflected in search results due to a short delay in indexing. We'll get that clarified in the documentation.

    For this kind of application, you may be better suited by directly checking with files_get_metadata though. I.e., you can check for 'printmessage=1' or 'printmessage=0' explicitly.

    Or, you can use files_list_folder to list the parent folder.

  • George K.23's avatar
    George K.23
    New member | Level 2
    10 years ago

    Hey, thanks for the reply. I've updated it to use files_list_folder instead, and the problem seems to have been solved :)

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!