Issue with directories

Hey there guys, I'm working on a program and I've run into some issues with which directoy things are happening in.

Basically the program is designed to provide the user with a list of programs, once the user selectes on it then provides the user with a list of all of the files with the related extension. Upon selecting a file it will then open the file with the desired program. My problem now is that my launch procedure and my scan procedure seem to operaterating in two seperate directories. Right now I simply have the folder containing the program on my desktop. When it runs it searches withing the folder, but when opening files it tries to open them out of the same folder's subfolder dir. I believe the problem is with the search, because when I copy the .exe to another location, for example the desktop, it will open folders from the desktop, if there happens to be a file with a matching name in my documents. However it won't open if there is no matching file on the desktop.

Here is the code how I have it now:


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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
#include <filesystem>
#include <vector>
#include <string>
#include <algorithm>
#include <fstream>
#include <Windows.h>
using namespace std;
using namespace std::tr2::sys;


bool ends_with(std::string& file, std::string& ext)
{
    return file.size() >= ext.size() && // file must be at least as long as ext
        // check strings are equal starting at the end
        std::equal(ext.rbegin(), ext.rend(), file.rbegin());
}

void wScan( path f, unsigned i = 0 )
{
	directory_iterator d( f );
	directory_iterator e;
	vector<string>::iterator it2;
	std::vector<string> extMatch;

	//iterate through all files
	for( ; d != e; ++d )
	{
		string file = d->path();
		string ext = ".docx";
		//populate vector with matching extensions
		if(ends_with(file, ext))
		{
			extMatch.push_back(file);
		}

	}
	//counter to appear next to file names
	int preI = -1;
	//display all matching file names and their counter
	for(it2 = extMatch.begin(); it2 != extMatch.end(); it2++)
	{
		preI += 1;
		cout << preI << ". " << *it2 << endl;
	}
	//ask for file selection and assign choice to fSelection
	cout << "Enter the number of your choice (or quit): ";
	int fSelection;
	cin >> fSelection;

	cout << extMatch[fSelection] << endl;

	//assign the selected file to a string, launch it based on that string and record and output time
		string s = extMatch[fSelection];
		unsigned long long start = ::GetTickCount64();
		system(s.c_str());
		unsigned long long stop = ::GetTickCount64();
		double elapsedTime = (stop-start)/1000.0;
		cout << "Time: " << elapsedTime << " seconds\n";

}


int main()
{

	string selection;
	cout << "0. Microsoft word \n1. Microsoft Excel \n2. Visual Studio 11 \n3. 7Zip \n4. Notepad \n Enter the number of your choice (or quit): ";

	cin >> selection;

	path folder = "..";

		if (selection == "0")
	{
		wScan ( folder );
	}
		else if (selection == "1")
	{
		eScan ( folder );
	}
		else if (selection == "2")
	{
		vScan ( folder );
	}
		else if (selection == "3")
	{
		zScan ( folder );
	}
		else if (selection == "4")
	{
		tScan ( folder );
	}
}


I'm also hoping to make changes so that I launch from the main, and have the file types as seperate classes. Including a while loop is also something I need to do so that I can request to open another file once the first has been closed. If you guys could offer any assistance with any of this it would be greatly appreicaited!
Topic archived. No new replies allowed.