Prechádzať zdrojové kódy

add get_top_level_dirs

quarrying 4 rokov pred
rodič
commit
1bdde7615e
1 zmenil súbory, kde vykonal 13 pridanie a 0 odobranie
  1. 13 0
      khandy/utils_fs.py

+ 13 - 0
khandy/utils_fs.py

@@ -100,6 +100,19 @@ def get_all_filenames(dirname, extensions=None, is_valid_file=None):
     return all_filenames
 
 
+def get_top_level_dirs(path, full_path=True):
+    if path is None:
+        path = os.getcwd()
+    path_ex = os.path.expanduser(path)
+    filenames = os.listdir(path_ex)
+    if full_path:
+        return [os.path.join(path_ex, item) for item in filenames
+                if os.path.isdir(os.path.join(path_ex, item))]
+    else:
+        return [item for item in filenames
+                if os.path.isdir(os.path.join(path_ex, item))]
+
+                
 def copy_file(src, dst_dir, action_if_exist=None):
     """
     Args: