Skip to main content

Categories: Ai, Directory

LIST_FILES

Lists files recursively from a source directory, adhering to the COPY INTO security model. Returns structured information about each file for use with AI functions and data processing workflows.

Syntax

LIST_FILES( source_path VARCHAR ) → TABLE( source VARCHAR, path VARCHAR, size BIGINT, last_modified_time TIMESTAMP )

  • source_path: The source path in format '@source_name/path/to/directory'. The source must be accessible via COPY INTO permissions.

Examples

LIST_FILES basic usage
SELECT 
file['path'] AS file_path,
file['size'] AS file_size,
file['last_modified_time'] AS modified_date
FROM TABLE(LIST_FILES('@my_source/documents'))
ORDER BY file['last_modified_time'] DESC;
-- file_path | file_size | modified_date
documents/report_2024.pdf | 2048576 | 2024-10-15 14:30:00
documents/summary_2024.txt | 512000 | 2024-10-14 09:15:00
documents/archive/old.pdf | 1024000 | 2024-09-01 11:00:00
LIST_FILES with filtering
SELECT 
file['path'] AS file_path,
file['size'] AS file_size
FROM TABLE(LIST_FILES('@my_source/documents'))
WHERE file['path'] LIKE '%.pdf'
AND file['size'] > 1000000
ORDER BY file['size'] DESC;
-- file_path | file_size
documents/large_report.pdf | 5242880
documents/manual.pdf | 2097152
documents/guide.pdf | 1572864
LIST_FILES with AI_GENERATE
SELECT 
file['path'] AS document,
AI_GENERATE(
'Extract the main topics from this document',
file
) AS topics
FROM TABLE(LIST_FILES('@my_source/documents'))
WHERE file['path'] LIKE '%.pdf';
-- document | topics
documents/report.pdf | Financial analysis, Market trends, Quarterly results
documents/whitepaper.pdf| Machine learning, Data processing, AI applications

Usage Notes

LIST_FILES returns a struct with the following fields:

source (VARCHAR): The source name
path (VARCHAR): The file path
size (BIGINT): File size in bytes
last_modified_time (TIMESTAMP): Last modification timestamp

Use with AI_GENERATE, AI_CLASSIFY, or AI_COMPLETE to process file contents.

Adheres to the same security model as COPY INTO for source access.