Removes every file in a directory. Args: path (str): Path to directory. Returns: None
(path: str)
| 23 | |
| 24 | |
| 25 | def clean_dir(path: str) -> None: |
| 26 | """ |
| 27 | Removes every file in a directory. |
| 28 | |
| 29 | Args: |
| 30 | path (str): Path to directory. |
| 31 | |
| 32 | Returns: |
| 33 | None |
| 34 | """ |
| 35 | try: |
| 36 | directory = Path(path).expanduser().resolve() |
| 37 | directory.mkdir(parents=True, exist_ok=True) |
| 38 | logger.info(f"Ensured directory exists: {directory}") |
| 39 | |
| 40 | for entry in directory.iterdir(): |
| 41 | if entry.is_dir(): |
| 42 | shutil.rmtree(entry) |
| 43 | logger.info(f"Removed directory: {entry}") |
| 44 | else: |
| 45 | entry.unlink(missing_ok=True) |
| 46 | logger.info(f"Removed file: {entry}") |
| 47 | |
| 48 | logger.info(colored(f"Cleaned {directory} directory", "green")) |
| 49 | except Exception as e: |
| 50 | logger.error(f"Error occurred while cleaning directory {path}: {str(e)}") |
| 51 | |
| 52 | |
| 53 | def choose_random_song() -> Optional[str]: |
no outgoing calls
no test coverage detected