list_files()
directory.list_files()
Get a list of files in directory (from your Diffgram service).
Parameters:
- page_num: the page number to fetch from the file list. Default is 1.
- limit: number of elements per page, Defaults to 25
- search_term: a string to search for a specific file.
- file_view_mode: a string that represents serializable data to include. Defaults to
annotation
. You can use valuebase
to get a smaller serializable version of the file with no annotations to improve performance.
file_object_list = directory.list_files()
Usage Example:
import logging
from diffgram import Project
project_literal = Project() # TODO add auth
dataset = project_literal.directory.get(name = "dataset_name") # TODO add name
logging.basicConfig(level=logging.INFO) # Optional, to show ID
file_list = dataset.list_files()
print("Length", len(file_list))
for file in file_list:
print(file.id)
print(file.original_filename)
Returns
INFO:root:Using Dataset ID 85855
Length 122
23231222
...
file_name
...
Pagination on List Files
If you want to access more than one page of the file_list, you can use the dataset.file_list_metadata
dictionary to get the current page number and iterate over all the available pages.
dataset_default = project.directory.get(name = "Default")
page_num = 1
all_files = []
while page_num != None:
print('Current page', page_num)
diffgram_files = dataset_default.list_files(limit = 1000, page_num = page_num, file_view_mode = 'base')
page_num = dataset_default.file_list_metadata['next_page']
print('Page {} of {}'.format(page_num, dataset_default.file_list_metadata['total_pages']))
all_files = all_files + diffgram_files
Updated over 3 years ago