Click here to Skip to main content
14,327,553 members

C / C++ / MFC

 
GeneralRe: C language Help using Dirent.h Pin
Richard MacCutchan24-May-15 2:19
protectorRichard MacCutchan24-May-15 2:19 
GeneralRe: C language Help using Dirent.h Pin
a random user24-May-15 2:51
membera random user24-May-15 2:51 
GeneralRe: C language Help using Dirent.h Pin
Richard MacCutchan24-May-15 3:08
protectorRichard MacCutchan24-May-15 3:08 
GeneralRe: C language Help using Dirent.h Pin
a random user24-May-15 4:08
membera random user24-May-15 4:08 
GeneralRe: C language Help using Dirent.h Pin
a random user24-May-15 5:17
membera random user24-May-15 5:17 
GeneralRe: C language Help using Dirent.h Pin
David Crow26-May-15 2:53
memberDavid Crow26-May-15 2:53 
GeneralRe: C language Help using Dirent.h Pin
David Crow26-May-15 2:51
memberDavid Crow26-May-15 2:51 
QuestionRe: C language Help using Dirent.h Pin
David Crow26-May-15 3:49
memberDavid Crow26-May-15 3:49 
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)
            {<br />
                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


QuestionRe: C language Help using Dirent.h Pin
David Crow26-May-15 2:48
memberDavid Crow26-May-15 2:48 
QuestionCString with non display characters Pin
ForNow22-May-15 6:00
memberForNow22-May-15 6:00 
SuggestionRe: CString with non display characters Pin
Richard MacCutchan22-May-15 7:15
protectorRichard MacCutchan22-May-15 7:15 
GeneralRe: CString with non display characters Pin
ForNow22-May-15 7:55
memberForNow22-May-15 7:55 
AnswerRe: CString with non display characters Pin
Richard Andrew x6422-May-15 12:26
professionalRichard Andrew x6422-May-15 12:26 
GeneralRe: CString with non display characters Pin
Richard MacCutchan22-May-15 22:14
protectorRichard MacCutchan22-May-15 22:14 
GeneralRe: CString with non display characters Pin
ForNow25-May-15 15:27
memberForNow25-May-15 15:27 
GeneralRe: CString with non display characters Pin
Chris Losinger26-May-15 3:29
professionalChris Losinger26-May-15 3:29 
AnswerRe: CString with non display characters Pin
Albert Holguin28-May-15 4:59
professionalAlbert Holguin28-May-15 4:59 
GeneralRe: CString with non display characters Pin
ForNow28-May-15 5:18
memberForNow28-May-15 5:18 
GeneralRe: CString with non display characters Pin
Albert Holguin28-May-15 7:49
professionalAlbert Holguin28-May-15 7:49 
Questioncode niblack c++ Pin
Member 1164373121-May-15 21:47
memberMember 1164373121-May-15 21:47 
SuggestionRe: code niblack c++ Pin
Richard MacCutchan21-May-15 23:14
protectorRichard MacCutchan21-May-15 23:14 
QuestionRe: code niblack c++ Pin
David Crow26-May-15 7:50
memberDavid Crow26-May-15 7:50 
QuestionMacTripleDES Encryption used in compromised Point-of-Sale (POS) Devices Pin
Member 1170583120-May-15 5:08
memberMember 1170583120-May-15 5:08 
AnswerRe: MacTripleDES Encryption used in compromised Point-of-Sale (POS) Devices Pin
Richard Andrew x6420-May-15 11:30
professionalRichard Andrew x6420-May-15 11:30 
AnswerRe: MacTripleDES Encryption used in compromised Point-of-Sale (POS) Devices Pin
CPallini20-May-15 20:36
mveCPallini20-May-15 20:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.