@@ -293,9 +293,12 @@ def _dir_model(self, path, content=True):
293293 model = self ._base_model (path )
294294 model ["type" ] = "directory"
295295 model ["size" ] = None
296+ model ["item_count" ] = None
296297 if content :
297298 model ["content" ] = contents = []
298299 os_dir = self ._get_os_path (path )
300+ dir_contents = os .listdir (os_dir )
301+ model ["item_count" ] = len (dir_contents )
299302 for name in os .listdir (os_dir ):
300303 try :
301304 os_path = os .path .join (os_dir , name )
@@ -334,7 +337,6 @@ def _dir_model(self, path, content=True):
334337 os_path ,
335338 exc_info = True ,
336339 )
337-
338340 model ["format" ] = "json"
339341
340342 return model
@@ -470,6 +472,7 @@ def _save_directory(self, os_path, model, path=""):
470472 if not os .path .exists (os_path ):
471473 with self .perm_to_403 ():
472474 os .mkdir (os_path )
475+ model ["item_count" ] = 0
473476 elif not os .path .isdir (os_path ):
474477 raise web .HTTPError (400 , "Not a directory: %s" % (os_path ))
475478 else :
@@ -765,10 +768,12 @@ async def _dir_model(self, path, content=True):
765768 model = self ._base_model (path )
766769 model ["type" ] = "directory"
767770 model ["size" ] = None
771+ model ["item_count" ] = None
768772 if content :
769773 model ["content" ] = contents = []
770774 os_dir = self ._get_os_path (path )
771775 dir_contents = await run_sync (os .listdir , os_dir )
776+ model ["item_count" ] = len (dir_contents )
772777 for name in dir_contents :
773778 try :
774779 os_path = os .path .join (os_dir , name )
0 commit comments