Hi,
I am trying to list all the files in a drive. when i use "*" instead of "C:\*" in findfirstfile() function then it works fine and lists all the files in the current directory but it does not work when i use "C:\*" and does not list files. can any one tell me plz that how can this can be made correct.thanx
#include "stdafx.h"
#include "fileinfor.h"
#include <iostream>
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include<conio.h>
#include <string>
#include <sstream>
#include <strsafe.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// The one and only application object
CWinApp theApp;
std::string convertWCharArrayToString(const WCHAR * const wcharArray) {
std::stringstream ss;
int i = 0;
char c = (char) wcharArray[i];
while(c != '\0') {
ss <<c;
i++;
c = (char) wcharArray[i];
}
std::string convert = ss.str();
return convert;
}
int main()
{
WIN32_FIND_DATA findFileData;
HANDLE hFind = FindFirstFile((LPCWSTR) "C:\*" , &findFileData);
if(hFind == INVALID_HANDLE_VALUE) {
std::cout <<"No files found." <<std::endl;
} else {
std::cout <<"Files found." <<std::endl;
}
int fileNumber = 0;
std::cout <<fileNumber <<":" <<convertWCharArrayToString(findFileData.cFileName) <<std::endl;
while(FindNextFile(hFind, &findFileData)) {
fileNumber++;
std::cout <<fileNumber <<":" <<convertWCharArrayToString(findFileData.cFileName) <<std::endl;
}
FindClose(hFind);
char a;
std::cin>> a;
return 0;
}