Commit cd8e80aa authored by rswindell's avatar rswindell
Browse files

Added getfilecount(), similar, but not identical to getdirsize().

parent 53f8e5ec
......@@ -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) */
/****************************************************************************/
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment