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

Callers

nothing calls this directly

Calls 2

FileSystemErrorClass · 0.90
resolveMethod · 0.80

Tested by

no test coverage detected