[GRASS-SVN] r56687 - grass/trunk/lib/python/pygrass

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jun 13 01:05:32 PDT 2013


Author: zarch
Date: 2013-06-13 01:05:32 -0700 (Thu, 13 Jun 2013)
New Revision: 56687

Modified:
   grass/trunk/lib/python/pygrass/functions.py
Log:
Add a function that return a list of files contained in a directory

Modified: grass/trunk/lib/python/pygrass/functions.py
===================================================================
--- grass/trunk/lib/python/pygrass/functions.py	2013-06-12 14:10:24 UTC (rev 56686)
+++ grass/trunk/lib/python/pygrass/functions.py	2013-06-13 08:05:32 UTC (rev 56687)
@@ -4,8 +4,8 @@
 
 @author: pietro
 """
-
 import fnmatch
+import os
 
 import grass.lib.gis as libgis
 import grass.lib.raster as libraster
@@ -28,6 +28,22 @@
     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):
     """Remove a map"""
     grasscore.run_command('g.remove', quiet=True,
@@ -133,7 +149,7 @@
     """Query a raster map for each point feature of a vector
 
     Example ::
-        
+
         >>> from grass.pygrass.vector import VectorTopo
         >>> from grass.pygrass.raster import RasterRow
         >>> ele = RasterRow('elevation')



More information about the grass-commit mailing list