Sign in to follow this  

Windows Directories problem

This topic is 3571 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to scan Windows Directories in a console program. But, it's not working. It finds all the files in the directory. However, there is the following text that shouldn't be there:(The following is the whole output)(The problem is those periods. It thinks those are files when they aren't.)
Quote:
Searching for files... . .. main.cpp palfix.dev Makefile.win main.o palfix.exe Done! Press any key to continue . . .
int main(int argc, char *argv[])
{
    WIN32_FIND_DATA dat;
    HANDLE search;
    
    printf("Searching for files...\n");
    search=FindFirstFile("*.*",&dat);
    if(search==INVALID_HANDLE_VALUE || ERROR_NO_MORE_FILES==GetLastError())
    {
    printf("Error: %s\n",GetLastError());
    }
    printf("%s\n",dat.cFileName);
    while(FindNextFile(search,&dat))
    {
                 printf("%s\n",dat.cFileName);
    }
    
    FindClose(search);
    
    printf("Done!\n");
    
    system("PAUSE");
    return EXIT_SUCCESS;
}



[Edited by - yellowstar on March 7, 2008 9:55:27 PM]

Share this post


Link to post
Share on other sites
There are valid files than can have a dot as the first char of the filename.
Check explicitely for the two filename "." and "..".
Check for the attribute flag FILE_ATTRIBUTE_DIRECTORY if you only want files.

Share this post


Link to post
Share on other sites
Quote:
Original post by yellowstar
*** Source Snippet Removed ***


Wrong, files and directories CAN start with a period. The single 'dot' refers to the current directory, while the double 'dot' refers to its parent directory.

Share this post


Link to post
Share on other sites
Quote:
Original post by Rydinare
You may want to take a look at Boost.Filesystem for things like this.


Download a library just to handle directorys/filesystems...
I guess it would be nice if it would fit into the following:(Since the website says it's portable)

1. Does it work on Windows,(Win98-Vista)
Linux, MAC OSX, ect.

2. Does it work with POSIX? That is, does it work with homebrew dev for Nintendo DS, Gamecube?(Wii too when we can do Wii HB)

Share this post


Link to post
Share on other sites

This topic is 3571 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this