Click here to Skip to main content
15,914,163 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create a simple text editor and then set all my .txt files to open my prgram. but when my programe starts i need the files location so i can access it.

I have manage to return the folder that the txt file is in. but cant seem to get the
text files name itself.

example: myText.txt.

What I have tried:

I use this code to return the directory of the txt file but i also need its name

char path[MAX_PATH];
std::cout << string(path,GetCurrentDirectory(sizeof(path), path)) << endl;
Posted
Updated 19-Mar-18 2:26am

If you are using your program on Windows, then Explorer should pass the document name (that is the text file) as command line argument to your application.
 
Share this answer
 
 
Share this answer
 
Comments
tylerberts 19-Mar-18 5:21am    
i ran your program and it dose what i need. i used it to open a file.iod (basicly a made up file extention) is there a way you could give a basic example that returns the file path in a string.
Check the input variables of the main function or the entry handler of the app object. There should be the full path in it.

Use the debugger.
 
Share this answer
 
Comments
tylerberts 19-Mar-18 5:07am    
do you mean argv[0] because that only returns the exe ive trided it.
For the sake of completion I have figuard it out. slap this in your code and you will get the location of the file that opened your programe. or what others call the file associated with it. or when you take a file type and right click. then click propertys and chose opens with and choose your programe. (I do not take credit i found it deep in the inter world lol)


#include <iostream>
int main( int argc, char* argv[] )
{
using namespace std;
cout << argc << " arguments:" << endl;
for( int i = 0; i < argc; ++i )
{
cout << "[" << argv[i] << "]" << endl;
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900