I'm still learning c++(hence the beginner forum) so please don't laugh at my code.
I'm basically making a program to copy a file, from user inputted file names, which actually works as posted below. However, I want to know if there's a way so the user (on windows system) can input the file name and my program will find it (the file to read from) EVEN IF IT'S IN SOME OTHER FOLDER OF THE C:\ DRIVE AND NOT IN THE SAME FOLDER AS MY PROJECT?
I'm aware my error checking is not great and plan on improving it, just wanted to get the files opening like I want and copying correctly (which it does do now)
int fileCopy(); //gets filenames and copies input file to user designated output file, returning -1 if unsuccessful
int check; //holds return value of fileCopy function to check if successful with file copying
cout<<"Sorry, the input or output file could not be opened. Please run again!"<<endl;
cout<<"You'r output file has been created successfully!";
cout<<"Please enter the name of the file you would like to copy: ";
cout<<endl<<"Please enter the name of the file you would like to copy "<<infileName<<" to: ";
if((!infile.is_open()) || (!outfile.is_open()))
if((infile.is_open()) && (outfile.is_open()))
and the cin>>x; at the end is the only way i can get the console window to stay open so i can see what the output of the program is.
A simple answer, no. Unless you know specifically what absolute folder it is in (starting with a drive letter), or what folder it is in relative to your executable, there is no easy way to do this quickly.
If you really needed to, you could search the entire drive to find the file, but even then you don't know if it is the correct file and it can take quite some time (I'm sure you've tried to search your drive before in Windows Explorer; it takes time.)