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.

Edited by daveoffy: n/a

6 Years
Discussion Span
Last Post by 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.


This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.