Start adding sync functions.

This commit is contained in:
James Grogan 2024-09-30 09:17:51 +01:00
parent 00325b36eb
commit b39807db44
10 changed files with 221 additions and 194 deletions

View file

@ -3,18 +3,29 @@ import os
import sys
def get_files_recursive(search_path: Path, extension: str) -> list[Path]:
return list(search_path.rglob(f"*.{extension}"))
def delete_empty_dirs_recursive(search_path: Path):
for curdir, subdirs, files in os.walk(search_path):
if len(subdirs) == 0 and len(files) == 0:
#print(curdir)
def get_files_recursive(path: Path, extensions: list[str] | None) -> list[Path]:
if not extensions:
return list(path.rglob("*.*"))
else:
ret = []
for ext in extensions:
ret.append(list(search_path.rglob(f"*.{ext}")))
return ret
def _delete_empty_dirs(path: Path) -> bool:
found_empty = False
for curdir, subdirs, files in os.walk(path):
if len(subdirs) == 0 and len(files) == 0:
found_empty = True
os.rmdir(curdir)
return found_empty
def delete_empty_dirs_recursive(path: Path):
found_empty = True
while found_empty:
found_empty = _delete_empty_dirs(path)
if __name__ == "__main__":
input_path = sys.argv[1]
print(input_path)
delete_empty_dirs_recursive(Path(input_path).resolve())
def replace_filename(path: Path, replacement: str) -> Path:
return path.parent / (replacement + path.suffix)