Run a file

2

My question is whether a file can be executed by its address (file path?).

For example, I want to execute the file that is in "C: \ Program Files \ Misc \ list.txt" and that the notepad with the file will open. As if I were opening it manually.

I searched for a lot of tutorials but most of them were about writing or reading the files, it's not what I need, I think. I am using Dev-C ++ (although I have no problems using Visual Studio 2017).

Greetings.

    
asked by DRAUXEN 28.11.2018 в 06:11
source

1 answer

0

You can use the system ( ) feature.

For example to open a file called foo.txt that is on your desktop with the notebook you should write:

system("notepad.exe C:\Users\<Tu Usuario>\Desktop\foo.txt");

Still, depending on the user Jona in the post , the use of system () is not recommended since it is not sure and affects the performance of the program, so you can use CreateProcess () , for more information about this function I leave the link to the Microsoft documentation both Spanish how to english .

    
answered by 30.11.2018 в 17:00