Using search results

Varsity

Newbie
Joined
Apr 13, 2004
Messages
2,683
Reaction score
2
Code:
  FindFirstFile("E:\\Documents and Settings\\",0);
  sr = FindNextFile;
  if(sr != INVALID_HANDLE_VALUE)
    {
      users.insert(iter,[b]what goes here?[/b]);
      FindClose(sr);
    }
    else
    {
      cout << "No users detected! Exiting...";
      return 0;
    }
I want to add teh search result to my vector. It works if I simply add a string so there's no issues with the rest of the code but I can't work out how to get at the values stored in sr. How do i do it?
 
I read the MSDN pages but they're way above my level. So's your code, although it works. But what I really want is to be able to insert the search results into my vector and I still haven't a cluse what part of the printf command does that.
 
The code he posted lists files in a directory. The line that prints them to the console is the printf line. findFileData.cFileName is the current file's filename. He loops round finding the next file each time, until there are no files left.

To add it to a vector simply put in your adding to a vector code where printf is.
 
users.insert(iter,"%s.\n", findFileData.cFileName) does not compile.
users.insert(iter,findFileData.cFileName) crashes at runtime.
 
Well, without knowing how to use vectors i can't really help you, sorry.

Do you understand parameter lists? I guess not, because if you did you'd know why users.insert(iter,"%s.\n", findFileData.cFileName) didn't compile (you gave the function 'insert' 3 parameters when i guess it only wants 2.

The 2nd line crashes probably because findFileData.cFileName isn't valid (you need to use FindFirstFile to initalize findFileData, which should make it's member functions/variables work corectly).
 
Akrin said:
Post more of your code.
Sounds like a plan.
Code:
// START MENU HANDLER
// Tom Edwards
// [email protected]

#include <iostream.h>
#include <windows.h>
#include <vector>

int RemAllUse() {
  system("cls");
  cout << endl << " Start Menu Handler 0.0.0 PRE-RELEASE" << endl << 
  "   >> Remove 'All Users' (Start Menu per user)" << endl << endl;
  return 0;
}

int ForAllUse() {
  system("cls");
  cout << endl << " Start Menu Handler 0.0.0 PRE-RELEASE" << endl << 
  "   >> Force 'All Users' (One shared Start Menu)" << endl << endl;
  return 0;
}

int MkSub() {
  system("cls");
  cout << endl << " Start Menu Handler 0.0.0 PRE-RELEASE" << endl << 
  "   >> Sort into subfolders" << endl << endl;
  return 0;
}

int RemSub() {
  system("cls");
  cout << endl << " Start Menu Handler 0.0.0 PRE-RELEASE" << endl << 
  "   >> Remove subfolders" << endl << endl;
  return 0;
}

int SortSM() {
  system("cls");
  cout << endl << " Start Menu Handler 0.0.0 PRE-RELEASE" << endl << 
  "   >> Sort Start Menu" << endl << endl;
  return 0;
}

int FindOrph() {
  system("cls");
  cout << endl << " Start Menu Handler 0.0.0 PRE-RELEASE" << endl << 
  "   >> Search for orphaned entries" << endl << endl;
  return 0;
}




int main() {

// BEGIN VARIABLE DECLARATIONS
  int i;
  vector<string> users(1);
  vector<string>::iterator iter = users.begin();
  short menuchoice;
  WIN32_FIND_DATA findFileData;
// END VARIABLE DECLARATIONS

// BEGIN VARIABLE INITILIZATION

// END VARIABLE INITILIZATION

  system("cls");
  cout << endl << " Start Menu Handler 0.0.0 PRE-RELEASE" << endl << endl;


  HANDLE hFind = FindFirstFile(_T("E:\\Documents and Settings\\*.*"), &findFileData);
if (hFind != INVALID_HANDLE_VALUE) {
    printf("%s.\n", findFileData.cFileName);

    bool finished = false;
    while (!finished)  {
        if (FindNextFile(hFind, &findFileData) != 0) {
            printf("%s.\n", findFileData.cFileName);
        }
        else {
            finished = true;
        }
    }

    FindClose(hFind);
}


/*
  FindFirstFile("E:\\Documents and Settings\\",0);
  sr = FindNextFile;
  if(sr != INVALID_HANDLE_VALUE)
    {
      users.insert(iter,);
      FindClose(sr);
    }
    else
    {
      cout << "No users detected! Exiting...";
      return 0;
    }

*/



// TODO - 1. Detect users 2. Find each users' start menu

// BEGIN MAIN MENU
  cout << 
  "  1. Remove 'All Users' (Start Menu per user)" << endl << 
  "  2. Force 'All Users' (One shared Start Menu)" << endl <<endl << 

  "  3. Sort into subfolders" << endl << 
  "  4. Remove subfolders" << endl << endl << 

  "  5. Sort Start Menu" << endl << endl << 

  "  6. Search for orphaned entries" << endl << endl <<
  "  7. Exit" << endl << endl << "  ";
// END MAIN MENU

  cin >> menuchoice;

  switch (menuchoice){
    case 1:
      RemAllUse();
      break;
    case 2:
      ForAllUse();
      break;
    case 3:
      MkSub();
      break;
    case 4:
      RemSub();
      break;
    case 5:
      SortSM();
      break;
    case 6:
      FindOrph();
      break;
    case 7:
      break;    
    default:
// TODO - learn how to restart program
      break;
}

}
 
Back
Top