Thread: Filenextfile

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    13

    Filenextfile

    Programming in visual c++. I got a editbox and a button on a form.
    when i press the button, the editbox gets filled with files and directorys.


    here is my code
    Code:
    HANDLE hFind;
    WIN32_FIND_DATA data;
    hFind = FindFirstFile("*.*", &data);
    if (hFind != INVALID_HANDLE_VALUE) {
     do 
     {
      
      
    GetDlgItem( testing )->SetWindowText( data.cFileName );
      
     }while(FindNextFile(hFind, &data));
      
    }

    i only get 1 item in the edit box..

    check the picture...
    Attached Images Attached Images Filenextfile-form-jpg 

  2. #2
    Registered User
    Join Date
    Nov 2012
    Posts
    13
    maybe use strcat?

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    13
    i solved it....

  4. #4
    Registered User
    Join Date
    Nov 2012
    Posts
    13
    i got it work but i cannot get the thigns on a new line

    Code:
    HANDLE hFind;
    WIN32_FIND_DATA data2;
    hFind = FindFirstFile("*.*", &data2);
    strcat(data,"\n");
    if (hFind != INVALID_HANDLE_VALUE) {
     while (FindNextFile(hFind, &data2)){
        if(FILE_ATTRIBUTE_DIRECTORY == data2.dwFileAttributes)
              strcat(data,"DIR");
    strcat(data,"\n");
      strcat(data,data2.cFileName);
    strcat(data,"\n");
     GetDlgItem( testing )->SetWindowText( data );
      } 
     
      FindClose(hFind);
    }
    can someone help me out with this?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    1. You start with
    strcat(data,"\n");
    but what is data initialised to? Is it a large char array filled with \0, or just an uninitialised pointer?

    2. Consider various combinations of \n and \r to create a newline

    3. Consider calling SetWindowText() at the end (just once), when you've finished scanning the directory.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed