Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

c++ console, possible to drag two files onto the exe, and store their names?

This topic is 4841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I want to make a console c++ app, and I was wondering if it was possible to drag two files onto the executable, so then the app can store their filenames? Does anyone know how this works, or where I can read information about it? I'm not really sure what to enter into a search engine for this. Thanks

Share this post


Link to post
Share on other sites
Advertisement
In Windows if you drag files onto the executable the filenames will be passed to the main() function through the argv parameter.

Share this post


Link to post
Share on other sites
Yup. Like this:


#include <string>
#include <iostream>

int main(int argc, char *argv[])
{
std::string params[argc];
for (int i = 1; i < argc; ++i)
params = argv;
for (int i = 0; i < argc; ++i)
std::cout << params << "\n";
std::cin.get();
return 0;
}



That code will store the full path of each file sent to the program in "params" and read them off to you. The first line is blank for me, but I think that sometimes it's the program name itself, like if you typed into the command prompt:

>readparams foo.txt bar.txt foobar.txt

you would get:

readparams
foo.txt
bar.txt
foobar.txt

There you go.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!