浏览代码

Add a function that return a list of files contained in a directory

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@56687 15284696-431f-4ddb-bdfa-cd5b030d7da7
Pietro Zambelli 12 年之前
父节点
当前提交
91b5842f3d
共有 1 个文件被更改,包括 18 次插入2 次删除
  1. 18 2
      lib/python/pygrass/functions.py

+ 18 - 2
lib/python/pygrass/functions.py

@@ -4,8 +4,8 @@ Created on Tue Jun 26 12:38:48 2012
 
 
 @author: pietro
 @author: pietro
 """
 """
-
 import fnmatch
 import fnmatch
+import os
 
 
 import grass.lib.gis as libgis
 import grass.lib.gis as libgis
 import grass.lib.raster as libraster
 import grass.lib.raster as libraster
@@ -28,6 +28,22 @@ def looking(obj, filter_string):
     return fnmatch.filter(word_list, filter_string)
     return fnmatch.filter(word_list, filter_string)
 
 
 
 
+def findfiles(dirpath, match=None):
+    """Return a list of the files"""
+    res = []
+    for f in sorted(os.listdir(dirpath)):
+        abspath = os.path.join(dirpath, f)
+        if os.path.isdir(abspath):
+            res.extend(findfiles(abspath, match))
+
+        if match:
+            if fnmatch.fnmatch(abspath, match):
+                res.append(abspath)
+        else:
+            res.append(abspath)
+    return res
+
+
 def remove(oldname, maptype):
 def remove(oldname, maptype):
     """Remove a map"""
     """Remove a map"""
     grasscore.run_command('g.remove', quiet=True,
     grasscore.run_command('g.remove', quiet=True,
@@ -133,7 +149,7 @@ def get_raster_for_points(poi_vector, raster, column=None):
     """Query a raster map for each point feature of a vector
     """Query a raster map for each point feature of a vector
 
 
     Example ::
     Example ::
-        
+
         >>> from grass.pygrass.vector import VectorTopo
         >>> from grass.pygrass.vector import VectorTopo
         >>> from grass.pygrass.raster import RasterRow
         >>> from grass.pygrass.raster import RasterRow
         >>> ele = RasterRow('elevation')
         >>> ele = RasterRow('elevation')