remove_by_pattern#

remove_by_pattern(directory: Union[str, cloudpathlib.cloudpath.CloudPath, pathlib.Path], name_with_wildcard: str = '*', extension: Optional[str] = None) None[source]#

Remove files corresponding to a pattern from a directory.

>>> directory = 'D:/path/to/folder'
>>> os.listdir(directory)
["huhu.exe", "blabla.geojson", "haha.txt", "blabla"]

>>> remove(directory, "blabla*")
>>> os.listdir(directory)
["huhu.exe", "haha.txt"] # Removes also directories

>>> remove(directory, "*", extension="txt")
>>> os.listdir(directory)
["huhu.exe"]
Parameters
  • directory (Union[str, CloudPath, Path]) – Directory where to find the files

  • name_with_wildcard (str) – Filename (wildcards accepted)

  • extension (str) – Extension wanted, optional. With or without point. (yaml or .yaml accepted)