- Microsoft C++
Should I just use Boost?
Tried using std::experimental::filesystem, it seems screwed.
The following code works, but does not search recursively
Should I just use Boost?
Tried using std::experimental::filesystem, it seems screwed.
Code
using namespace std;
namespace fs = std::experimental::filesystem;The following code works, but does not search recursively
Code
#include <windows.h>
#include <tchar.h>
#include <shlobj.h>
#include <string.h>
#include <stdio.h>
#include <strsafe.h>
#pragma comment(lib, "User32.lib")
#include <iostream>
using namespace std;
void DisplayErrorBox(LPTSTR lpszFunction);
int _tmain(int argc, TCHAR* argv[])
{
WIN32_FIND_DATA ffd;
LARGE_INTEGER filesize;
TCHAR szDir[MAX_PATH];
HANDLE hFind = INVALID_HANDLE_VALUE;
DWORD dwError = 0;
TCHAR path[MAX_PATH];
TCHAR subpath[MAX_PATH];
// If the directory is not specified as a command-line argument,
// print usage.
if (SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, 0, path) != S_OK)
{
cout << "I could not retrieve the user's home directory!\n";
}
else
{
}
// Prepare string for use with FindFile functions. First, copy the
// string to a buffer, then append '\*' to the directory name.
StringCchCopy(szDir, MAX_PATH, path);
StringCchCat(szDir, MAX_PATH, TEXT("\\*"));
// Find the first file in the directory.
hFind = FindFirstFile(szDir, &ffd);
if (INVALID_HANDLE_VALUE == hFind)
{
_tprintf(TEXT("FindFirstFile"));
return dwError;
}
// List all the files in the directory with some info about them.
do
{
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
filesize.LowPart = ffd.nFileSizeLow;
filesize.HighPart = ffd.nFileSizeHigh;
_tprintf(TEXT(" %s\\%s +DIR \n"), path, ffd.cFileName);
}
else
{
filesize.LowPart = ffd.nFileSizeLow;
filesize.HighPart = ffd.nFileSizeHigh;
_tprintf(TEXT(" %s\\%s \n"),path, ffd.cFileName);
}
} while (FindNextFile(hFind, &ffd) != 0);
dwError = GetLastError();
if (dwError != ERROR_NO_MORE_FILES)
{
_tprintf(TEXT("FindFirstFile"));
}
FindClose(hFind);
return dwError;
}
