snowflake.snowpark.FileOperation.remove¶

FileOperation.remove(stage_location: str, *, pattern: Optional[str] = None, statement_params: Optional[Dict[str, str]] = None) → List[str][source]¶

Removes files from a stage.

References: Snowflake REMOVE command.

Example:

>>> # Create a temp stage and upload files.
>>> _ = session.sql("create or replace temp stage mystage").collect()
>>> _ = session.file.put("tests/resources/testCSV.csv", "@mystage/prefix1")
>>> _ = session.file.put("tests/resources/testCSV.csv", "@mystage/prefix2")
>>> # Remove all files from the stage.
>>> session.file.remove("@mystage/prefix1")
['mystage/prefix1/testCSV.csv.gz']
>>> # Remove files matching a pattern.
>>> session.file.remove("@mystage/prefix2", pattern=".*test.*")
['mystage/prefix2/testCSV.csv.gz']
Copy
Parameters:
  • stage_location – The stage and path where you want to remove files.

  • pattern – Specifies a regular expression pattern for filtering files to remove. 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 removed).

  • statement_params – Dictionary of statement level parameters to be set while executing this action.

Returns:

A list of removed file paths.