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 :
#include<iostream>
#include<conio.h>
#include<fstream>
#include<stdio.h>
#include<stdlib.h>
#include <windows.h>
#include <string>
#include <cstdlib>
int main (int argc, constchar * argv[])
{
usingnamespace 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;
}
#include<iostream>
#include<conio.h>
#include<fstream>
#include<stdio.h>
#include<stdlib.h>
#include <windows.h>
#include <string>
#include <cstdlib>
int main (int argc, constchar * argv[])
{
usingnamespace 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;
}