浏览代码

add get_top_level_dirs

quarrying 4 年之前
父节点
当前提交
1bdde7615e
共有 1 个文件被更改,包括 13 次插入0 次删除
  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: