Skip to content

Commit 92c0652

Browse files
committed
Catch exception in get_size/get_modification_date when file does not exists
1 parent cfdb38d commit 92c0652

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

tests/test_filebrowser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ def test_filebrowser_keybrowse(self):
110110
# --- openfile
111111
fb = FileBrowser(self.window, initialdir="/", mode="openfile",
112112
multiple_selection=True)
113+
if not fb.hide:
114+
fb.toggle_hidden()
113115
self.window.update()
114116
fb.right_tree.focus_force()
115117
self.window.update()

tkfilebrowser/constants.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ def remove_trace(variable, mode, cbname):
152152

153153
def get_modification_date(file):
154154
"""Return the modification date of file."""
155-
tps = fromtimestamp(os.path.getmtime(file))
155+
try:
156+
tps = fromtimestamp(os.path.getmtime(file))
157+
except OSError:
158+
tps = TODAY
156159
date = locale_date(tps)
157160
if date == TODAY:
158161
date = _("Today") + tps.strftime(" %H:%M")
@@ -163,7 +166,10 @@ def get_modification_date(file):
163166

164167
def get_size(file):
165168
"""Return the size of file."""
166-
size_o = os.path.getsize(file)
169+
try:
170+
size_o = os.path.getsize(file)
171+
except OSError:
172+
size_o = 0
167173
if size_o > 0:
168174
m = int(floor(log(size_o) / log(1024)))
169175
if m < len(SIZES):

0 commit comments

Comments
 (0)