以编程方式为Windows中的文件夹创建快捷方式 [英] Programmatically create shortcuts for folders in Windows

查看:129
本文介绍了以编程方式为Windows中的文件夹创建快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件夹A和一个文件夹B.对于A中的每个子文件夹,我需要检查B是否包含指向该子文件夹的链接.如果没有,我需要创建它.

I have a folder A and a folder B. For each subfolder inside A I need to check if B contains a link to that subfolder. If not, I need to create it.

我当前正在使用此页面上的代码创建链接:创建文件快捷方式(.lnk) 我的问题是此代码始终创建文件快捷方式,而不是文件夹快捷方式,因此,如果我尝试打开快捷方式,它将不会打开相应的文件夹.有人知道如何创建文件夹快捷方式吗?

I'm currently creating the links using the code found on this page: Creating a file shortcut (.lnk) My problem is that this code always creates a file shortcut, not a folder shortcut, so if I try to open the shortcut it does not open the corresponding folder. Anyone knows how to create folder shortcuts instead?

推荐答案

我会回答自己的问题,因为我发现很多人在网上问这个问题,却没人提供答案.

I'll answer my own question because I found lots of people asking this on the web and nobody providing an answer.

通过反复试验,我发现如果您使用Path.GetFullPath方法计算要分配给TargetPath属性的值,则输出的格式将被识别为文件夹路径,因此系统会自动将其标识为文件夹快捷方式并分配相应的图标.

I found through trial and error that if you use the Path.GetFullPath method to calculate the value to assign to the TargetPath property, the output is in a format that's recognized as a folder path, so the system will automatically identify it as a folder shortcut and assign the corresponding icon.

这篇关于以编程方式为Windows中的文件夹创建快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆