> I want to get the list of all the files with extension *.seq present
> in a directory and its sub-directories.
> I tried GetFirstFile and GetNextFile but this gets files from the
> directory specified and not from its sub-directories.
- Do that in a function to which you pass the directory name.
- Loop on all the files, build 2 lists, one global with the file names and one local to the
function with the subdirectories names.
- AFTER that, loop on all the found subdirectories and pass them recursively to the same function.
You cannot call recursively directly because GetFirst/NextFile use internal static allocations and
cannot be recursed.
There may be a better way (either with Windows API or with newer CVI functions), but this has been
working for me since DOS 2.0 !!!
Here's a piece of my code I just grepped from I don't know what old dead project:
static void CreateIndexIn(char* DirName) {
char SearchFor[MAX_PATHNAME_LEN], FileName[MAX_FILENAME_LEN], IndexName[MAX_PATHNAME_LEN],
SubName[MAX_PATHNAME_LEN];
int Found=0, i;
ListType DirList;
DirList = ListCreate(MAX_FILENAME_LEN);
sprintf(IndexName, "%s\\%s", DirName, INDEX);
CreateIndex(IndexName);
// Search directories
sprintf(SearchFor, "%s\\*", DirName);
Found=GetFirstFile (SearchFor, 0, 0, 0, 0, 0, 1, FileName);
while (Found==0) {
ListInsertItem(DirList, FileName, END_OF_LIST);
Found = GetNextFile (FileName);
}
// Search for all files
sprintf(SearchFor, "%s\\*.jpg", DirName);
Found=GetFirstFile (SearchFor, 1, 1, 0, 0, 1, 0, FileName);
while (Found==0) {
if (strstr (FileName, ".jpg")!=NULL or strstr (FileName, ".JPG")!=NULL or
strstr (FileName, ".jpeg")!=NULL or strstr (FileName, ".JPEG")!=NULL or
strstr (FileName, ".gif")!=NULL or strstr (FileName, ".GIF")!=NULL or
strstr (FileName, ".png")!=NULL or strstr (FileName, ".PNG")!=NULL)
Something;
else
SomethingElse;
Found = GetNextFile (FileName);
}
// Recurse to all subdirs
for (i=1; i<=ListNumItems (DirList); i++) {
ListGetItem (DirList, FileName, i);
sprintf(SubName, "%s\\%s", DirName, FileName);
CreateIndexIn(SubName);
}
ListDispose (DirList);
}
--
Guillaume Dargaud
http://www.gdargaud.net/
"It's 5.50 a.m.... Do you know where your stack pointer is ?"