Skip to main content
gamedev.net
🔒 Locked

Windows Directories problem

Started by yellowstar 6 replies 1.5k views
Original Post
yellowstar
yellowstar
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]
My Website:link(Not hosted by Gamedev)
Antheus
Antheus
Quote:
Original post by yellowstar

(The problem is those periods. It thinks those are files when they aren't.)


Read the description. It allows you to filter the results.
Hodgman
Hodgman
...    while(FindNextFile(search,&dat))    {         if( dat.cFileName && dat.cFileName[0] != '.' )                 printf("%s\n",dat.cFileName);    }...
Endurion
Endurion
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.
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>
yellowstar
yellowstar
Quote:
Original post by Hodgman
*** Source Snippet Removed ***


That worked.

bool IsRealFile(char *filename){         if(filename[0]=='.')return 0;          return 1;}

My Website:link(Not hosted by Gamedev)
RavenKnight
RavenKnight
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.
Rydinare
Rydinare
You may want to take a look at Boost.Filesystem for things like this.
yellowstar
yellowstar
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)
My Website:link(Not hosted by Gamedev)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.