Download Programming with lcc-win32
Transcript
Using function pointers
p = strchr(q,';');
// Cut the specification at the separator char.
if (p)
*p = 0;
h = FindFirstFile(q,&data);
if (h != INVALID_HANDLE_VALUE) {
do {
if (!(data.dwFileAttributes &
FILE_ATTRIBUTE_DIRECTORY)) {
// We have found a matching file. Call the user’s function.
sprintf(fullname,"%s\\%s",dir,data.cFileName);
if (!fn(fullname))
return 0;
}
} while (FindNextFile(h,&data));
FindClose(h);
}
// Restore the input specification. It would be surprising for the user of this
// application that we destroyed the character string that was passed to
// this function.
if (p)
*p++ = ';';
// Advance q to the next specification
q = p;
} while (q);
// OK. We have done all the files in this directory. Now look if there are any
// subdirectories in it, and if we found any, recurse.
hdir = FindFirstFile("*.*",&dirdata);
if (hdir != INVALID_HANDLE_VALUE) {
do {
if (dirdata.dwFileAttributes &
FILE_ATTRIBUTE_DIRECTORY) {
// This is a directory entry. Ignore the “.” and “..” entries.
if (! (dirdata.cFileName[0] == '.' &&
(dirdata.cFileName[1] == 0 ||
dirdata.cFileName[1] == '.'))) {
// We change the current dir to the subdir and recurse
chdir(dirdata.cFileName);
ScanFiles(spec,fn);
// Restore current directory to the former one
chdir(dir);
}
}
} while (FindNextFile(hdir,&dirdata));
FindClose(hdir);
}
return 1;
}
This function above could be used in a program like this:
static int files; // used to count the number of files seen
// This is the callback function. It will print the name of the file and increment a counter.
int printfile(char *fname)
{
printf("%s\n",fname);
files++;
return 1;
}
// main expects a specification, and possibly a starting directory. If no starting directory
// is given, it will default to the current directory.
153
Related documents
Programming with lcc
Programming with lcc-win
C-Tutorial
Manuel d`utilisation de Version 1.3
IOTech Personal488 DOS and Windows3.X User Manual
WinCE manual for OEM - Future Design Controls
E SPOT III User Manual ver 1
Platinum Spot III User Manual ver 1
Platinum SBX User Manual ver 1
Cygwin User's Guide
OmniFlop User Guide
Cygwin User's Guide