Dec 23, 2020 at 2:20pm UTC
I am using that code to enumerate files with specific extensions in a drive and write them out to a text file.
std::ofstream file;
file.open("test.txt", std::ios::out | std::ios::app | std::ios::binary);
std::list<CString> listFiles;
FindFiles(_T("D:\\"), _T(".txt"), listFiles);
for (const auto& strFile : listFiles)
file << strFile.GetString() << std::endl;
return 0;
It outputs something like this in the text file. How can I write their address with their names instead of this garbage,
00000281BBACF338
00000281BBACEA78
00000281BBACF108
00000281BBAD1E48
00000281BBAD3D38
00000281BBAD3248
00000281BBAD22F8
Last edited on Dec 23, 2020 at 2:21pm UTC
Dec 23, 2020 at 4:51pm UTC
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#include <Windows.h>
#include <atlpath.h>
#include <list>
#include <iostream>
#include <fstream>
#ifdef _UNICODE
#define cout wcout
#endif
void FindFiles(
const CString& strRootPath,
const CString& strExt,
std::list<CString>& listFiles,
bool bRecursive = true )
{
CString strFileToFind = strRootPath;
ATLPath::Append(CStrBuf(strFileToFind, MAX_PATH), _T("*.*" ));
WIN32_FIND_DATA findData = { 0 };
HANDLE hFileFind = ::FindFirstFile(strFileToFind, &findData);
if (INVALID_HANDLE_VALUE != hFileFind)
{
do
{
CString strFileName = findData.cFileName;
if ((strFileName == _T("." )) || (strFileName == _T(".." )))
continue ;
CString strFilePath = strRootPath;
ATLPath::Append(CStrBuf(strFilePath, MAX_PATH), strFileName);
if (bRecursive && (ATLPath::IsDirectory(strFilePath)))
{
FindFiles(strFilePath, strExt, listFiles);
}
else
{
CString strFoundExt = ATLPath::FindExtension(strFilePath);
if (!strExt.CompareNoCase(strFoundExt))
listFiles.push_back(strFilePath);
}
} while (::FindNextFile(hFileFind, &findData));
::FindClose(hFileFind);
}
}
int main()
{
std::ofstream file;
file.open("test.txt" , std::ios::out | std::ios::app | std::ios::binary);
std::list<CString> listFiles;
FindFiles(_T("D:\\" ), _T(".txt" ), listFiles);
for (const auto & strFile : listFiles)
file << (LPCTSTR)strFile.GetString() << std::endl;
return 0;
}
Thank you for replying.
//But it Still outputs this
0000017F883B31E8
0000017F883B4138
0000017F883B3648
0000017F883B3AA8
0000017F883B4598
Last edited on Dec 24, 2020 at 12:56am UTC