unsigned long DirList(const char * dirpath, CharBuf &buf, const char separator ){ if (!dirpath) return 0; WIN32_FIND_DATA fdata; size_t l=strlen(dirpath); buf.Clear(); if (!buf.AddArray(dirpath,l)) return 0; if (dirpath[l-1]!='\\') if (!buf.Add('\\')) return 0; if (!buf.AddArray("*.*\0",4)) return 0; HANDLE fhandle = FindFirstFile(buf.GetBuf(),&fdata); if (fhandle == (HANDLE) -1) return 0; unsigned long items=0; BOOL res=FALSE; buf.Clear(); do { if (!buf.AddArray(fdata.cFileName,strlen(fdata.cFileName))) break; if (!buf.Add(separator)) break; items++; res = FindNextFile(fhandle,&fdata); } while (res); FindClose(fhandle); buf.Add('\0'); return items;}
int main(int argc, char *argv[]){ CharBuf buf; DirList("D:",buf); puts(buf.GetBuf());}