snowflake.snowpark.FileOperation.list¶
- FileOperation.list(stage_location: str, *, pattern: Optional[str] = None, statement_params: Optional[Dict[str, str]] = None) List[ListResult] [source]¶
Returns a list of files from a stage.
References: Snowflake LIST command.
Example:
>>> # Create a temp stage and upload files. >>> _ = session.sql("create or replace temp stage mystage").collect() >>> _ = session.file.put("tests/resources/t*.csv", "@mystage/prefix1") >>> # List all files in the stage. >>> list_result = session.file.list("@mystage/prefix1") >>> assert len(list_result) > 0 >>> # List files matching a pattern. >>> filtered_result = session.file.list("@mystage/prefix1", pattern=".*test.*") >>> assert len(filtered_result) > 0
- Parameters:
stage_location – The stage and path from which you want to list files.
pattern – Specifies a regular expression pattern for filtering files from the output. The command lists all files in the specified path and applies the regular expression pattern on each of the files found. Default:
None
(all files in the specified stage path are listed).statement_params – Dictionary of statement level parameters to be set while executing this action.
- Returns:
A
list
ofListResult
instances, each of which represents the metadata of a file in the stage.