I am working on a "searching" program. But it always returns a "." as the up directory or whatever. And I can't do an if statement to check if its a period or not.

The goal is to get the only name of the folder in that directory. There is only 1 folder but the name always changes. If you have a better way of doing this please tell.

WIN32_FIND_DATA FindProfileName;
    HANDLE hFind;
    char *filepath;
    char *foldername;
//...Other Code Here to set filepath
hFind = FindFirstFile(filepath, &FindProfileName);
    if (FindProfileName.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
        foldername = FindProfileName.cFileName;
        printf("\nFolder: %s", foldername);
        if(foldername == ".")
            printf("\nPeriod Returned\n");

Thanks in advance.


Since the folder always ends in a "t" I added *t so it would search for anything that has a t at the end.

Member Avatar for MonsieurPointer

I know this is a terribly old thread, but I hope I can still pitch in and help. After a FindFirstFile, FindNextFile is usually called in a loop, but only if FindFirstFile does not return INVALID_HANDLE_VALUE. Once you are done, you will need to close the handle with FindClose.

When using FindFirstFile to search for directories, the first result is always ".", provided the search directory is valid. The very first call with FindNextFile is then "..". Everything else after that are directories you are interested in.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.