mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-04 18:25:22 +03:00
Cleanup directory remover
This commit is contained in:
parent
b6a78f82a4
commit
34767270bd
@ -2,20 +2,18 @@
|
||||
|
||||
import os
|
||||
|
||||
from frigate.const import RECORD_DIR
|
||||
|
||||
|
||||
def remove_empty_directories(directory):
|
||||
def remove_empty_directories(directory: str) -> None:
|
||||
# list all directories recursively and sort them by path,
|
||||
# longest first
|
||||
paths = sorted(
|
||||
[x[0] for x in os.walk(RECORD_DIR)],
|
||||
[x[0] for x in os.walk(directory)],
|
||||
key=lambda p: len(str(p)),
|
||||
reverse=True,
|
||||
)
|
||||
for path in paths:
|
||||
# don't delete the parent
|
||||
if path == RECORD_DIR:
|
||||
if path == directory:
|
||||
continue
|
||||
if len(os.listdir(path)) == 0:
|
||||
os.rmdir(path)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user