如何从通过链接开始可执行文件的位置获取目录的名称?
我写了一个小程序,该程序应该根据其位于其中的文件夹的名称更改一些文本文件。 只要可执行文件也位于文件夹中,这也可以正常工作。 但是,对于程序没有很多副本,我想通过链接启动它。 如何找到触发可执行文件的链接的位置? 我尝试过:
let path_parts: Vec<_> = env::current_dir().unwrap()
.components()
.map(|part| part.as_os_str().to_ascii_lowercase())
.collect();
但是在Win10下运行,只要可执行文件在汇编的目标目录中,这确实可以工作。可执行文件移至另一个位置,它将给出目录名称,即可执行文件所在的位置,而不是链接。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在Windows上,链接到程序包含应该启动程序的位置。这默认为可执行文件的文件夹,但是可以通过编辑链接属性(例如使用
alt-enter
或从上下文菜单中选择“属性”)来更改。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).