File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -718,3 +718,25 @@ def _trace_dir_upwards(path: Path) -> Path:
718718 path = Path (path )
719719 prefix = _trace_dir_upwards (path )
720720 return PosixPathPair (prefix , path .relative_to (prefix ))
721+
722+
723+ def normalize_path_name (
724+ path : str | Path , replacements : dict [str , str ] | None = None
725+ ) -> Path :
726+ """Normalize the name of a path.
727+
728+ :param path: A path to be normalized.
729+ :param replacements: A mapping of characters to replace.
730+ """
731+ if isinstance (path , str ):
732+ path = Path (path )
733+ name = path .name
734+ if replacements is None :
735+ replacements = {
736+ " " : "_" ,
737+ "(" : "_" ,
738+ ")" : "_" ,
739+ }
740+ path_new = path .with_name (name .translate (str .maketrans (replacements )))
741+ path .rename (path_new )
742+ return path_new
You can’t perform that action at this time.
0 commit comments