Commit b3eac84d authored by rswindell's avatar rswindell
Browse files

Change getfilecount() to allow the pattern to be specified (or not) in the path

argument, eliminate the spec/pattern argument.
parent 93f4f04b
...@@ -449,7 +449,7 @@ const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen, long* pmode) ...@@ -449,7 +449,7 @@ const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen, long* pmode)
if(strncmp(sp, "FILES:", 6) == 0) { // Number of files in specified directory if(strncmp(sp, "FILES:", 6) == 0) { // Number of files in specified directory
const char* path = getpath(&cfg, sp + 6); const char* path = getpath(&cfg, sp + 6);
safe_snprintf(str, maxlen, "%lu", getfilecount(path, ALLFILES)); safe_snprintf(str, maxlen, "%lu", getfilecount(path));
return str; return str;
} }
......
...@@ -792,10 +792,10 @@ long DLLCALL delfiles(const char *inpath, const char *spec, size_t keep) ...@@ -792,10 +792,10 @@ long DLLCALL delfiles(const char *inpath, const char *spec, size_t keep)
} }
/****************************************************************************/ /****************************************************************************/
/* Returns number of files in a directory (inpath) matching 'pattern' */ /* Returns number of files matching 'inpath' */
/* Similar, but not identical, to getdirsize(), e.g. subdirs never counted */ /* Similar, but not identical, to getdirsize(), e.g. subdirs never counted */
/****************************************************************************/ /****************************************************************************/
ulong DLLCALL getfilecount(const char *inpath, const char* pattern) ulong DLLCALL getfilecount(const char *inpath)
{ {
char path[MAX_PATH+1]; char path[MAX_PATH+1];
glob_t g; glob_t g;
...@@ -803,8 +803,10 @@ ulong DLLCALL getfilecount(const char *inpath, const char* pattern) ...@@ -803,8 +803,10 @@ ulong DLLCALL getfilecount(const char *inpath, const char* pattern)
ulong count = 0; ulong count = 0;
SAFECOPY(path, inpath); SAFECOPY(path, inpath);
backslash(path); if(isdir(path))
SAFECAT(path, pattern); backslash(path);
if(IS_PATH_DELIM(*lastchar(path)))
SAFECAT(path, ALLFILES);
if(glob(path, GLOB_MARK, NULL, &g)) if(glob(path, GLOB_MARK, NULL, &g))
return 0; return 0;
for(gi = 0; gi < g.gl_pathc; ++gi) { for(gi = 0; gi < g.gl_pathc; ++gi) {
......
...@@ -228,7 +228,7 @@ DLLEXPORT char* DLLCALL getfname(const char* path); ...@@ -228,7 +228,7 @@ DLLEXPORT char* DLLCALL getfname(const char* path);
DLLEXPORT char* DLLCALL getfext(const char* path); DLLEXPORT char* DLLCALL getfext(const char* path);
DLLEXPORT int DLLCALL getfattr(const char* filename); DLLEXPORT int DLLCALL getfattr(const char* filename);
DLLEXPORT int DLLCALL getfmode(const char* filename); DLLEXPORT int DLLCALL getfmode(const char* filename);
DLLEXPORT ulong DLLCALL getfilecount(const char *inpath, const char* spec); DLLEXPORT ulong DLLCALL getfilecount(const char *path);
DLLEXPORT char* DLLCALL getdirname(const char* path); DLLEXPORT char* DLLCALL getdirname(const char* path);
DLLEXPORT long DLLCALL getdirsize(const char* path, BOOL include_subdirs, BOOL subdir_only); 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 getdisksize(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