Listing files in directory problem

My attempt to list all files/folders in a directory:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
wstring files[999];

void getfiles(wstring targetdir)
{
unsigned int inn=1;
WIN32_FIND_DATA filedata;
HANDLE hFind = INVALID_HANDLE_VALUE;
hFind = FindFirstFileW(targetdir.c_str(), &filedata);
if (hFind == INVALID_HANDLE_VALUE) 
{cout<<"ERROR:  returned invalid handle\n";system("pause");} 
else
{
cout<<"[0] - ";wcout<<filedata.cFileName<<endl; files[0]=filedata.cFileName;;
while (FindNextFileW(hFind, &filedata) != 0) 
{
cout<<'['<<inn<<']'<<" - ";wcout<<filedata.cFileName<<endl; files[inn]=filedata.cFileName;inn++;
 if(GetLastError()!=0){cout<<"ERROR: "<<GetLastError()<<endl;system("pause");SetLastError(0);}
}
FindClose(hFind);
}
}


The first two items listed are always
[0] - .
and
[1] - ..
for any directory other than C:\\. Subsequent items are listed correctly until the program reaches a folder or file that contains non-ASCII characters. For example, the output for a folder containing "PPヨ摠ヨ" is
everything up to this point is correct (except [0] and [1])
[83] - PP[84] - [85] - [86] - [87] 

and so on until the end of the directory is reached, even though all file names after [84] contain only ASCII characters. Even the endl is ignored. GetLastError() returns 18 after [1] and then 0; the project is set to use Unicode characters.

Any ideas what I might be doing wrong (besides the poor formatting)?
The display problem is caused due to the font of your console.
Then one more:
windows puts the directory
.
..
these represent the current directory and parent directory...
Thank you - 2 out of 3 issues resolved.

Edit: changed the font, still nothing

2nd Edit: My mistake you were correct, topic solved.
Last edited on
Thankyou, you are welcome all the time...
Topic archived. No new replies allowed.