MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeWiki / cleanup_directory

Function cleanup_directory

codewiki/cli/utils/fs.py:163–189  ·  view source on GitHub ↗

Clean up a directory by removing its contents. Args: path: Directory to clean keep_hidden: Keep hidden files/directories (starting with .) Raises: FileSystemError: If cleanup fails

(path: Path, keep_hidden: bool = True)

Source from the content-addressed store, hash-verified

161 """
162 Clean up a directory by removing its contents.
163
164 Args:
165 path: Directory to clean
166 keep_hidden: Keep hidden files/directories (starting with .)
167
168 Raises:
169 FileSystemError: If cleanup fails
170 """
171 path = Path(path).expanduser().resolve()
172
173 if not path.exists():
174 return
175
176 try:
177 for item in path.iterdir():
178 if keep_hidden and item.name.startswith("."):
179 continue
180
181 if item.is_file():
182 item.unlink()
183 elif item.is_dir():
184 shutil.rmtree(item)
185 except Exception as e:
186 raise FileSystemError(f"Cannot clean directory {path}: {e}")

Callers

nothing calls this directly

Calls 2

FileSystemErrorClass · 0.90
resolveMethod · 0.80

Tested by

no test coverage detected