-
1 Attachment(s)
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...
-
-
-
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?
-
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.