16 # include <sys/types.h>
17 # include <sys/stat.h>
18 # include <sys/time.h>
31 #include "find_files.h"
33 #include <sys/types.h>
39 void find_files_by_pattern(const char* pattern
, svector
<char *>& filenames
)
42 if (!glob(pattern
, 0, NULL
, &g
))
44 for (int i
= 0; i
< g
.gl_pathc
; ++i
)
47 stat(g
.gl_pathv
[i
],&cstat
);
48 if(!S_ISREG(cstat
.st_mode
))continue;
50 // don't include the path
51 char* src
= strrchr(g
.gl_pathv
[i
], '/');
54 int len
= strlen(++src
);
55 char* c
= new char[len
+ 1]; // caller will free this
57 filenames
.push_back(c
);
64 void find_files_by_pattern_with_exception(const char* pattern
, svector
<char *>& filenames
,const char *exception
)
67 if (!glob(pattern
, 0, NULL
, &g
))
69 for (int i
= 0; i
< g
.gl_pathc
; ++i
)
72 stat(g
.gl_pathv
[i
],&cstat
);
73 if(!S_ISREG(cstat
.st_mode
))continue;
75 // don't include the path
76 char* src
= strrchr(g
.gl_pathv
[i
], '/');
79 int len
= strlen(++src
);
80 if(!strcmp(src
,exception
))continue;
82 char* c
= new char[len
+ 1]; // caller will free this
84 filenames
.push_back(c
);
91 void find_files_by_pattern(const char* pattern
, stringvectst
& filenames
)
94 if (!glob(pattern
, 0, NULL
, &g
))
96 for (int i
= 0; i
< g
.gl_pathc
; ++i
)
99 stat(g
.gl_pathv
[i
],&cstat
);
100 if(!S_ISREG(cstat
.st_mode
))continue;
102 // don't include the path
103 char* src
= strrchr(g
.gl_pathv
[i
], '/');
107 filenames
.add_string(src
);
114 void find_files_by_pattern_with_exception(const char* pattern
, stringvectst
& filenames
,const char *exception
)
117 if (!glob(pattern
, 0, NULL
, &g
))
119 for (int i
= 0; i
< g
.gl_pathc
; ++i
)
122 stat(g
.gl_pathv
[i
],&cstat
);
123 if(!S_ISREG(cstat
.st_mode
))continue;
125 // don't include the path
126 char* src
= strrchr(g
.gl_pathv
[i
], '/');
130 if(!strcmp(src
,exception
))continue;
132 filenames
.add_string(src
);
139 void find_directories_by_pattern(const char* pattern
, stringvectst
&filenames
)
142 if (!glob(pattern
, 0, NULL
, &g
))
144 for (int i
= 0; i
< g
.gl_pathc
; ++i
)
147 stat(g
.gl_pathv
[i
],&cstat
);
148 if(!S_ISDIR(cstat
.st_mode
))continue;
150 // don't include the path
151 char* src
= strrchr(g
.gl_pathv
[i
], '/');
155 filenames
.add_string(src
);
162 void find_directories_by_pattern_with_exception(const char* pattern
, stringvectst
&filenames
,const char *exception
)
165 if (!glob(pattern
, 0, NULL
, &g
))
167 for (int i
= 0; i
< g
.gl_pathc
; ++i
)
170 stat(g
.gl_pathv
[i
],&cstat
);
171 if(!S_ISDIR(cstat
.st_mode
))continue;
173 // don't include the path
174 char* src
= strrchr(g
.gl_pathv
[i
], '/');
178 if(!strcmp(src
,exception
))continue;
180 filenames
.add_string(src
);