Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get the name of the directory from where an executable via link was started?

I have written a small program which should change some text files according to the name of the folder they are located in.
This works fine as long as the executable is in the folder, too.
But to not have many copies of the program I would like to start it via a link.
How do I find find the location of the link which has triggered the executable?
I tried:

let path_parts: Vec<_> = env::current_dir().unwrap()
    .components()
    .map(|part| part.as_os_str().to_ascii_lowercase())
    .collect();

But running under win10 this does only work as long as the executable is in the target directory where it was compiled. The executable moved to another location, it will give the directory name, where the executable is located, not the link.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

On Windows, links to programs contain the location in which the program should be started. This defaults to the folder of the executable, but can be changed by editing the link properties (e.g. with Alt-Enter or choosing "Properties" from the context menu).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading