Skip to content

Commit

Permalink
Update folder_monitor.py
Browse files Browse the repository at this point in the history
  • Loading branch information
theanine3D authored Jan 18, 2024
1 parent 39f2304 commit dbbeb6f
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions folder_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,23 @@ def on_any_event(self, event):
elif event.event_type in ('created', 'modified', 'deleted'):
rel_path = os.path.relpath(event.src_path, self.watch_dir)
timestamp = strftime('%H:%M:%S - %Y-%m-%d',localtime())
filesize = os.path.getsize(event.src_path)
filesize = None
try:
filesize = os.path.getsize(event.src_path)
except:
pass
filesize_unit = "B"
if filesize >= 1048576:
filesize = filesize / 1024 / 1024
filesize_unit = "MB"
elif filesize >= 1024:
filesize = filesize / 1024
filesize_unit = "KB"
print(f"{timestamp} - {event.event_type.capitalize()}: - {rel_path} - {round(filesize,2)} {filesize_unit}")
if filesize != None:
if filesize >= 1048576:
filesize = filesize / 1024 / 1024
filesize_unit = "MB"
elif filesize >= 1024:
filesize = filesize / 1024
filesize_unit = "KB"
line = f"{timestamp} - {event.event_type.capitalize()}: - {rel_path}"
if filesize != None:
line += f" - {round(filesize,2)} {filesize_unit}"
print(line)

def monitor_directory(directory_to_watch):
global watcher, thread
Expand Down

0 comments on commit dbbeb6f

Please sign in to comment.