From: Calin Crisan Date: Fri, 7 Mar 2014 20:11:06 +0000 (+0200) Subject: removing media files now cleans up the empty dirs X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=7a42de8cd40b2ba263f182178bd5c7b170f09574;p=motioneye-debian removing media files now cleans up the empty dirs --- diff --git a/src/mediafiles.py b/src/mediafiles.py index a770834..4a046b1 100644 --- a/src/mediafiles.py +++ b/src/mediafiles.py @@ -102,10 +102,13 @@ def _remove_older_files(dir, moment, exts): for (full_path, st) in _list_media_files(dir, exts): file_moment = datetime.datetime.fromtimestamp(st.st_mtime) if file_moment < moment: - logging.debug('removing file %(path)s...' % { - 'path': full_path}) + logging.debug('removing file %(path)s...' % {'path': full_path}) os.remove(full_path) + dir_path = os.path.dirname(full_path) + if not os.listdir(dir_path): + logging.debug('removing directory %(path)s...' % {'path': dir_path}) + os.removedirs(dir_path) def find_ffmpeg():