Problem with Files Listing on windows

Hi all of you guys ,
i want to make a listing programe that lists specific folder files into a text file . but i have some problems with unicode file names !!
whene i execute that simple code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<iostream>
#include<conio.h>
#include<fstream>
#include<stdio.h>
#include<stdlib.h>
#include <windows.h>
#include <string>
#include <cstdlib>

int main (int argc, const char * argv[])
{
using namespace std;	
wchar_t short_path[MAX_PATH] ;									
	std::wstring path=L"C://Myfolder/*";  // this is my path that i wish to list
	wfstream scr;	// this for handling our output to a text file	
    WIN32_FIND_DATAW search_data;
    memset(&search_data, 0, sizeof(WIN32_FIND_DATA));
    HANDLE handle = FindFirstFileW(path.c_str(), &search_data);
    int inc=0; // just for counting number of files
    scr.open("screen.txt"); // text file where we want to stor our results 
    while(handle != INVALID_HANDLE_VALUE)
   		{
   			std::wstring sfileName = search_data.cFileName;	
   			//GetShortPathNameW( sfileName.c_str(), short_path, MAX_PATH ) ;  
   			scr<<sfileName<<endl;
   			inc++;
   			if(FindNextFileW(handle, &search_data) == FALSE) break;
	    		
   				}
				   cout<<inc;// gives us 7 which mean it finds all 5 files .	

   FindClose(handle);
   scr.close();
return 0;

}

the output is like that :
https://image.ibb.co/eXDqXa/Screenshot_1.png
then when i try this code (short path code ):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<iostream>
#include<conio.h>
#include<fstream>
#include<stdio.h>
#include<stdlib.h>
#include <windows.h>
#include <string>
#include <cstdlib>

int main (int argc, const char * argv[])
{

	using namespace std;
	wchar_t short_path[MAX_PATH] ;
	std::wstring path=L"C://Myfolder/*";	// this is my path that i wish to list
	wfstream scr;	// this for handling our output to a text file	
    WIN32_FIND_DATAW search_data;
    memset(&search_data, 0, sizeof(WIN32_FIND_DATA));
    HANDLE handle = FindFirstFileW(path.c_str(), &search_data);
    int inc=0; // just for counting number of files
    scr.open("screen.txt"); // text file where we want to stor our results 
    while(handle != INVALID_HANDLE_VALUE)
   		{
   			std::wstring sfileName = search_data.cFileName;	
   			GetShortPathNameW( sfileName.c_str(), short_path, MAX_PATH ) ;  
   			scr<<short_path<<endl;
   			inc++;
   			if(FindNextFileW(handle, &search_data) == FALSE) break;
	    		
   				}
				   cout<<inc;// gives us 7 which mean it finds all 5 files .	

   FindClose(handle);
   scr.close();


return 0;

}

i get good result :
https://image.ibb.co/kJuayF/Screenshot_2.png

please can anyone help me on understanding that ?
and how to list all files even unicode named files ?
thank you all ,
Last edited on
Topic archived. No new replies allowed.