Index: src/lib/osunix.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/osunix.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -b -B -U 4 -r1.41 -r1.42
--- src/lib/osunix.c	7 Jun 2009 07:11:55 -0000	1.41
+++ src/lib/osunix.c	8 Jul 2009 16:24:25 -0000	1.42
@@ -11,8 +11,10 @@
 #include <termios.h>
 #include "portable.h"
 #include "portimpl.h"
 #include <sys/wait.h>
+#include <regex.h>
+
 
 static char const rcsid[] = "$Id$";
 
 
@@ -116,8 +118,41 @@
 slNameSort(&list);
 return list;
 }
 
+struct slName *listDirRegEx(char *dir, char *regEx, int flags)
+/* Return an alphabetized list of all files that match 
+ * the regular expression pattern in directory.
+ * See REGCOMP(3) for flags (e.g. REG_ICASE)  */
+{
+struct slName *list = NULL, *name;
+struct dirent *de;
+DIR *d;
+regex_t re;
+int err = regcomp(&re, regEx, flags | REG_NOSUB);
+if(err)
+    errAbort("regcomp failed; err: %d", err);
+
+if ((d = opendir(dir)) == NULL)
+    return NULL;
+while ((de = readdir(d)) != NULL)
+    {
+    char *fileName = de->d_name;
+    if (differentString(fileName, ".") && differentString(fileName, ".."))
+	{
+	if (!regexec(&re, fileName, 0, NULL, 0))
+	    {
+	    name = newSlName(fileName);
+	    slAddHead(&list, name);
+	    }
+	}
+    }
+closedir(d);
+regfree(&re);
+slNameSort(&list);
+return list;
+}
+
 struct fileInfo *newFileInfo(char *name, off_t size, bool isDir, int statErrno, 
 	time_t lastAccess)
 /* Return a new fileInfo. */
 {

