reading files

hello
I wrote a c++ program that takes files as input. the problem is that I have about 1000 files to input to the program and you bet that it's kind of hard to enter each filename manually. so I would like to save all the files in a directory and write a piece of code that automatically selects all the files in the directory, one after another, and input them in the program. Does someone know how to? I will definitely appreciate.

Comments

  • : hello
    : I wrote a c++ program that takes files as input. the problem is that I have about 1000 files to input to the program and you bet that it's kind of hard to enter each filename manually. so I would like to save all the files in a directory and write a piece of code that automatically selects all the files in the directory, one after another, and input them in the program. Does someone know how to? I will definitely appreciate.
    :

    Just get yourself to the directory and use FindFirstFile() & FindNextFile() to step through the files, sending a pointer one at a time to your function.
    [CODE]
    void CLoopfilesDlg::OnButton1()
    {
    HANDLE dir;
    WIN32_FIND_DATA fd;
    char*fname;

    dir = FindFirstFile( "*.*", &fd );
    if( dir == NULL )
    {
    [GREEN]//
    // error_message: "Could not open current directory"
    //[/GREEN]
    exit( 1 );
    }
    [GREEN]//
    // Loop through all the files in the directory
    //[/GREEN]
    while ( 1 )
    {
    [GREEN]//
    // Make sure we are not passing a Directory name
    //[/GREEN]
    if( !(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
    {
    [GREEN]//
    //Get the long file name
    //[/GREEN]
    fname = fd.cFileName;
    [GREEN]//
    // TODO: PassPointerToYourFunction(fname);
    //[/GREEN]
    }
    [GREEN]//
    // Get the next file
    //[/GREEN]
    if( !FindNextFile( dir, &fd ) )
    {
    break;
    }

    }
    FindClose( dir );
    }
    [/CODE]
  • heloo DB1,
    this is just what I was looking for. Thanks a lot!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories