Hi, me an my friend are creating a program that requires locating files, which requires knowing the file path. We came across functions to find the user name of the current person logged into windows, and to find all the logical drives on the target computer. We need help passing the information gained from these functions into the findfile function . Here's our code:
#include "stdafx.h"
#include <iostream>
#include <io.h>
#include <time.h>
#include <string>
#include <windows.h>
#include <direct.h>
#include <stdio.h>
#include <tchar.h>
#include <Lmcons.h>
using namespace std;
void DumpEntry(_finddata_t &data)
{
if (data.attrib & _A_SUBDIR == _A_SUBDIR)
{
cout << "[" << data.name << "]" << endl;
}
else
{
cout << data.name << endl;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR name [ UNLEN + 1 ];
DWORD size = UNLEN + 1;
if (GetUserName( (TCHAR*)name, &size ))
wcout << L"Hello, " << name << L"!\n";
else
cout << "Hello, unnamed person!\n";
TCHAR szBuffer[1024];
::GetLogicalDriveStrings(1024, szBuffer);
TCHAR *pch = szBuffer;
while (*pch) {
_tprintf(TEXT("%s\n"), pch);
pch = &pch[_tcslen(pch) + 1];
}
_finddata_t data;
int ff = _findfirst ("/Users/ /AppData/Local/Microsoft/Windows/*.*", &data);
if (ff != -1)
{
int res = 0;
while (res != -1)
{
DumpEntry(data);
res = _findnext(ff, &data);
}
_findclose(ff);
}
return 0;
}
We need to pass the logical drive letter before /Users and we need to pass the username in between /Users and /AppData.