2222
2323
2424import psutil
25- from os import walk , mkdir
25+ from os import walk , mkdir , stat
2626from os .path import exists , join , getmtime , realpath , split , expanduser , \
2727 abspath , isabs , splitext , dirname , getsize , isdir , isfile , islink
2828try :
3333import traceback
3434import tkfilebrowser .constants as cst
3535from tkfilebrowser .constants import unquote , tk , ttk , key_sort_files , \
36- get_modification_date , get_size
36+ get_modification_date , display_modification_date , display_size
3737from tkfilebrowser .autoscrollbar import AutoScrollbar
3838from tkfilebrowser .path_button import PathButton
3939from tkfilebrowser .tooltip import TooltipTreeWrapper
@@ -699,15 +699,19 @@ def _display_recents(self):
699699 ext = splitext (f )[- 1 ]
700700 if extension == ["" ] or ext in extension :
701701 tags .append ("file_link" )
702- vals = (p , get_size (p ), get_modification_date (p ))
702+ stats = stat (p )
703+ vals = (p , display_size (stats .st_size ),
704+ display_modification_date (stats .st_mtime ))
703705 elif isdir (p ):
704706 tags .append ("folder_link" )
705707 vals = (p , "" , get_modification_date (p ))
706708 elif isfile (p ):
707709 ext = splitext (f )[- 1 ]
708710 if extension == ["" ] or ext in extension :
709711 tags .append ("file" )
710- vals = (p , get_size (p ), get_modification_date (p ))
712+ stats = stat (p )
713+ vals = (p , display_size (stats .st_size ),
714+ display_modification_date (stats .st_mtime ))
711715 elif isdir (p ):
712716 tags .append ("folder" )
713717 vals = (p , "" , get_modification_date (p ))
@@ -969,9 +973,18 @@ def display_folder_walk(self, folder, reset=True, update_bar=True):
969973 tags = tags + (str (i % 2 ),)
970974 i += 1
971975
972- self .right_tree .insert ("" , "end" , p , text = f , tags = tags ,
973- values = ("" , get_size (p ),
974- get_modification_date (p )))
976+ try :
977+ stats = stat (p )
978+ except OSError :
979+ self .right_tree .insert ("" , "end" , p , text = f , tags = tags ,
980+ values = ("" ,
981+ display_size (0 ),
982+ display_modification_date (cst .TODAY )))
983+ else :
984+ self .right_tree .insert ("" , "end" , p , text = f , tags = tags ,
985+ values = ("" ,
986+ display_size (stats .st_size ),
987+ display_modification_date (stats .st_mtime )))
975988 else :
976989 for f in files :
977990 ext = splitext (f )[- 1 ]
@@ -990,9 +1003,18 @@ def display_folder_walk(self, folder, reset=True, update_bar=True):
9901003 tags = tags + (str (i % 2 ),)
9911004 i += 1
9921005
993- self .right_tree .insert ("" , "end" , p , text = f , tags = tags ,
994- values = ("" , get_size (p ),
995- get_modification_date (p )))
1006+ try :
1007+ stats = stat (p )
1008+ except OSError :
1009+ self .right_tree .insert ("" , "end" , p , text = f , tags = tags ,
1010+ values = ("" ,
1011+ display_size (0 ),
1012+ display_modification_date (cst .TODAY )))
1013+ else :
1014+ self .right_tree .insert ("" , "end" , p , text = f , tags = tags ,
1015+ values = ("" ,
1016+ display_size (stats .st_size ),
1017+ display_modification_date (stats .st_mtime )))
9961018 items = self .right_tree .get_children ("" )
9971019 if items :
9981020 self .right_tree .focus_set ()
@@ -1052,17 +1074,17 @@ def display_folder_scandir(self, folder, reset=True, update_bar=True):
10521074 else :
10531075 tags = tags + (str (i % 2 ),)
10541076 i += 1
1055- stat = f .stat ()
1077+ stats = f .stat ()
10561078 if b_file :
10571079 if (extension == ["" ] or splitext (name )[- 1 ] in extension ):
10581080 self .right_tree .insert ("" , "end" , f .path , text = name , tags = tags ,
10591081 values = ("" ,
1060- cst . display_size (stat .st_size ),
1061- cst . display_modification_date (stat .st_mtime )))
1082+ display_size (stats .st_size ),
1083+ display_modification_date (stats .st_mtime )))
10621084 else :
10631085 self .right_tree .insert ("" , "end" , f .path , text = name , tags = tags ,
10641086 values = ("" , "" ,
1065- cst . display_modification_date (stat .st_mtime )))
1087+ display_modification_date (stats .st_mtime )))
10661088 items = self .right_tree .get_children ("" )
10671089 if items :
10681090 self .right_tree .focus_set ()
0 commit comments