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.

Ur code seems confusing and does not really have good labels for variables. Then afterwards u have no basic idea presented to us on how u want to use this data, try creating a better version of the FindFile Function so we can help u pass the paramters and make it work cleaner.

>>We need to pass the logical drive letter before /Users and we need to pass the username in between /Users and /AppData.

Well, that is pretty trival thing to do. Just create a std::string

std::string path;
path = pch;
path += "Users\\";
path += username;
path += "\\AppData\\Local\\Microsoft\\Windows\\*.*";

int ff = _findfirst(path.c_str());
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.