<?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: Searching for a specific file type in Discuss Dropbox Developer &amp; API</title>
    <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Searching-for-a-specific-file-type/m-p/424161#M1243</link>
    <description>&lt;P&gt;I'm glad to hear you already got this working. You have the right idea in that you can call&amp;nbsp;&lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox.Dropbox.files_list_folder" target="_self"&gt;files_list_folder&lt;/A&gt; to list the contents of a folder, and then check the&amp;nbsp;&lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/files.html#dropbox.files.Metadata.path_lower" target="_self"&gt;Metadata.path_lower&lt;/A&gt; (or&amp;nbsp;&lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/files.html#dropbox.files.Metadata.name" target="_self"&gt;Metadata.name&lt;/A&gt;) for the returned entries to see if the file extension is one you're interested in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note though that you should also implement&amp;nbsp;&lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox.Dropbox.files_list_folder_continue" target="_self"&gt;files_list_folder_continue&lt;/A&gt; to make sure you can receive all of the entries. Check out &lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox.Dropbox.files_list_folder" target="_self"&gt;the&amp;nbsp;files_list_folder documentation&lt;/A&gt; for more information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, one alternative for your file extension check may be to use the 'endswith' method like this:&lt;/P&gt;
&lt;PRE&gt;files.path_lower.endswith(".jpg")&lt;/PRE&gt;</description>
    <pubDate>Tue, 26 May 2020 17:12:13 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2020-05-26T17:12:13Z</dc:date>
    <item>
      <title>Searching for a specific file type</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Searching-for-a-specific-file-type/m-p/423773#M1238</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;I'll ask for some patience and forgiveness in advance.&amp;nbsp; Im about 2 weeks in to Python devleopment, so Im likely missing some obvious approaches - please dont assume a lot of knowledge on my part if you can help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Objective:&amp;nbsp; I've been tasked with 'crawling' through folders on DropBox via the API to look for certain image types (specific file extensions only - *.dco for reference&amp;nbsp; - as I wont have knowledge of the file names), and then extracting the path and filename (and then 'do stuff').&amp;nbsp; Locally I have already completed this code (in other words, if the files are on my computer it works fine) - but now it needs to work in DropBox as well because the data sets will be quite large.&amp;nbsp; I cannot assume that the files in the folders will be the types I want - hence I need to search for filename extensions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have access to the DropBox and authorization sorted.&amp;nbsp; I've created a folder and put in some temp files (which are the pdf's and jpeg's provided by DropBox for testing).&amp;nbsp; I can query the folder, and return a list of results via files_list_folder.&lt;/P&gt;
&lt;P&gt;I can get a list of files, extensions and paths via the code below - however the issue I am having is that I cannot parse the data based on file extension, and the rudementary methods I am using are not working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While I can get a list of files, and even 'copy' them to another list - I cannot find a way to parse the list to give me the path_lower/ the directory and filename - which will give me the extension (ie: find all *.jpg's).&amp;nbsp; I must be missing something in the manner in which the data is constructed (I understand its instance/object based).&amp;nbsp; I have been assuming Im not hitting on the correct keyword combinations to extract the data - so Im looking for some help in identifying where Im going wrong.&amp;nbsp; Thanks in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;my_client=Dropbox(token)
folderfile_list = my_client.files_list_folder('', True, True)

#this gives me a nice list of items - however I dont seem to be able to *do* anything with it
for item in folderfile_list.entries:
    if isinstance(item, dropbox.files.FileMetadata):
        name = item.name
        fileID= item.id
        fileHash = item.content_hash
        path= metadata.path_lower
        print(name, path)

#This does return the search results I want - but its not iterable - so I dont seem to be able to do anything with it
files_search = my_client.files_search('', '*.pdf')
print(files_search)

type(files_search)
Out[325]: &amp;lt;class 'dropbox.files.SearchResult'&amp;gt;


#this returns nothing
for files in folderfile_list.entries:
    if files.path_lower == '*.jpg':
        print("yes")

#this returns nothing
for item in folderfile_list.entries:
    if entry.path_lower == '*.jpg':
        print("I got it")
    else:
        print("still nothing")
&lt;BR /&gt;#this also doesnt work
import fnmatch
pattern ='*.jpg'
matching = fnmatch.filter(folderfile_list.entries, pattern)
print(matching)&lt;BR /&gt;&lt;BR /&gt;fname = []&lt;BR /&gt;for i in folderfile_list.entries:&lt;BR /&gt;fname.append(i)&lt;BR /&gt;print(fname[1])&lt;BR /&gt;&lt;BR /&gt;import fnmatch&lt;BR /&gt;pattern ='*.jpg'&lt;BR /&gt;matching = fnmatch.filter(fname, pattern)&lt;BR /&gt;print(matching)

#this did work - however I cannot find a file TYPE with this - the specific file #name I can find - but not the file extension&lt;BR /&gt;#In other words if I change this it *.pdf - it does not get a 'happy' result :(
for files in fname:
    if files.path_lower == '/test folder/strategy-session-hotel.pdf':
        print("happy")
        print(files.path_lower)
    else:
        print('unhappy')&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 May 2020 05:22:00 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Searching-for-a-specific-file-type/m-p/423773#M1238</guid>
      <dc:creator>Bin2</dc:creator>
      <dc:date>2020-05-26T05:22:00Z</dc:date>
    </item>
    <item>
      <title>Re: Searching for a specific file type</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Searching-for-a-specific-file-type/m-p/423827#M1239</link>
      <description>&lt;P&gt;I believe I have solved my own problem - incase anyone else needs it.&amp;nbsp; Its not pretty - but it works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;spot=[]
holder=[]
holder=dbx.files_list_folder('/Test Folder')
print(holder)
for files in holder.entries:
  spot.append(files.path_lower)
 
print(spot)

pattern = '*.jpg'
matching = fnmatch.filter(spot, pattern)
print(matching)

['/test folder/az-car-rental.jpg', '/test folder/il-car-rental.jpg', '/test folder/car-rental-invoice.jpg', '/test folder/dinner-receipt.jpg', '/test folder/lunch-receipt.jpg', '/test folder/meal-receipt.jpg', '/test folder/meetup-dinner.jpg', '/test folder/team-offsite-lunch.jpg', '/test folder/training-airfare.jpg', '/test folder/training-hotel-invoice.jpg', '/test folder/travel-meal.jpg']&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 May 2020 19:16:02 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Searching-for-a-specific-file-type/m-p/423827#M1239</guid>
      <dc:creator>Bin2</dc:creator>
      <dc:date>2020-05-25T19:16:02Z</dc:date>
    </item>
    <item>
      <title>Re: Searching for a specific file type</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Searching-for-a-specific-file-type/m-p/424161#M1243</link>
      <description>&lt;P&gt;I'm glad to hear you already got this working. You have the right idea in that you can call&amp;nbsp;&lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox.Dropbox.files_list_folder" target="_self"&gt;files_list_folder&lt;/A&gt; to list the contents of a folder, and then check the&amp;nbsp;&lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/files.html#dropbox.files.Metadata.path_lower" target="_self"&gt;Metadata.path_lower&lt;/A&gt; (or&amp;nbsp;&lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/files.html#dropbox.files.Metadata.name" target="_self"&gt;Metadata.name&lt;/A&gt;) for the returned entries to see if the file extension is one you're interested in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note though that you should also implement&amp;nbsp;&lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox.Dropbox.files_list_folder_continue" target="_self"&gt;files_list_folder_continue&lt;/A&gt; to make sure you can receive all of the entries. Check out &lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox.Dropbox.files_list_folder" target="_self"&gt;the&amp;nbsp;files_list_folder documentation&lt;/A&gt; for more information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, one alternative for your file extension check may be to use the 'endswith' method like this:&lt;/P&gt;
&lt;PRE&gt;files.path_lower.endswith(".jpg")&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 May 2020 17:12:13 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Searching-for-a-specific-file-type/m-p/424161#M1243</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2020-05-26T17:12:13Z</dc:date>
    </item>
  </channel>
</rss>

