snowflake.snowpark.DataFrameReader.file

DataFrameReader.file(path: str) DataFrame[source]

Returns a DataFrame with a single column FILE containing a list of files in the specified Snowflake stage location (either internal or external).

Parameters:

path – The stage location to list files from (e.g., “@mystage”, “@mystage/path/”).

Example:

>>> # Create a temp stage and upload some test files
>>> _ = session.sql("CREATE OR REPLACE TEMP STAGE mystage").collect()
>>> _ = session.file.put("tests/resources/testCSV.csv", "@mystage", auto_compress=False)
>>> _ = session.file.put("tests/resources/testCSVheader.csv", "@mystage", auto_compress=False)
>>> _ = session.file.put("tests/resources/testJson.json", "@mystage", auto_compress=False)

>>> # List all files in the stage
>>> df = session.read.file("@mystage")
>>> df.count()
3

>>> # List files matching a pattern (only CSV files)
>>> df = session.read.option("pattern", ".*\.csv").file("@mystage")
>>> df.count()
2

>>> # List files with a more specific pattern
>>> df = session.read.option("pattern", ".*header.*").file("@mystage")
>>> df.count()
1
Copy

This function or method is experimental since 1.37.0.