Nothing personal, but this code looks all kinds of convoluted. When iterating the items in the folder pointed to by argv[1], how are you determining if an item is a file or a folder? [edit] Upon further inspection, I now see that code in dirent.h is a wrapper for this. My bad. [/edit] I suspect you need to be using the _findfirst()/_findnext() pair, or _stat() at the very minimum. It's been ages since I've used the former, but I envision something like:
void processFile( const char *pFile )
{
// however you need to handle 'pFile' would go here
}
//====================================================================
void processFolder( const char *pFolder )
{
char *p = (char *) malloc(strlen(pFolder) + 5);
strcpy(p, pFolder);
strcat(p, "\\*.*");
struct \_finddata\_t fileinfo;
intptr\_t handle = \_findfirst(p, &fileinfo);
if (handle != -1)
{
do
{
if (fileinfo.attrib & \_A\_SUBDIR)
{
if (fileinfo.name\[0\] != '.')
processFolder(fileinfo.name);
}
else
processFile(fileinfo.name);
} while(\_findnext(handle, &fileinfo) == 0);
\_findclose(handle);
}
free(p);
}
//====================================================================
void main(int argc, char* argv[])
{
if (argc == 2)
processFolder(argv[1]);
}
Obviously this does not solve your overall problem, but you can't bother with checking the contents of a file before you have successfully iterated a folder.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles