diff --git a/src/xpdev/dirwrap.c b/src/xpdev/dirwrap.c index eb8e46a58fb14095e869cd0ad4ff2c7b6f74cb35..5bfbaa2edee2acce873a3431907b342289a98f37 100644 --- a/src/xpdev/dirwrap.c +++ b/src/xpdev/dirwrap.c @@ -300,6 +300,10 @@ void DLLCALL globfree(glob_t* glob) #endif /* !defined(__unix__) */ +/****************************************************************************/ +/* Returns number of files and/or sub-directories in directory (path) */ +/* Similar, but not identical, to getfilecount() */ +/****************************************************************************/ long DLLCALL getdirsize(const char* path, BOOL include_subdirs, BOOL subdir_only) { char match[MAX_PATH+1]; @@ -735,6 +739,31 @@ ulong DLLCALL delfiles(const char *inpath, const char *spec) return(files); } +/****************************************************************************/ +/* Returns number of files in a directory (inpath) matching 'pattern' */ +/* Similar, but not identical, to getdirsize(), e.g. subdirs never counted */ +/****************************************************************************/ +ulong DLLCALL getfilecount(const char *inpath, const char* pattern) +{ + char path[MAX_PATH+1]; + glob_t g; + uint gi; + ulong count = 0; + + SAFECOPY(path, inpath); + backslash(path); + strcat(path, pattern); + if(glob(path, GLOB_MARK, NULL, &g)) + return 0; + for(gi = 0; gi < g.gl_pathc; ++gi) { + if(*lastchar(g.gl_pathv[gi]) == '/') + continue; + count++; + } + globfree(&g); + return count; +} + /****************************************************************************/ /* Return free disk space in bytes (up to a maximum of 4GB) */ /****************************************************************************/ diff --git a/src/xpdev/dirwrap.h b/src/xpdev/dirwrap.h index e1203fb45104d387d57a88f4a6627149e76c1339..dd3de391ee8bc5010658abf0cdec21534a3ebc9c 100644 --- a/src/xpdev/dirwrap.h +++ b/src/xpdev/dirwrap.h @@ -227,6 +227,7 @@ DLLEXPORT BOOL DLLCALL isfullpath(const char* filename); DLLEXPORT char* DLLCALL getfname(const char* path); DLLEXPORT char* DLLCALL getfext(const char* path); DLLEXPORT int DLLCALL getfattr(const char* filename); +DLLEXPORT ulong DLLCALL getfilecount(const char *inpath, const char* spec); DLLEXPORT long DLLCALL getdirsize(const char* path, BOOL include_subdirs, BOOL subdir_only); DLLEXPORT ulong DLLCALL getdisksize(const char* path, ulong unit); DLLEXPORT ulong DLLCALL getfreediskspace(const char* path, ulong unit);