在 C# 中复制快捷方式后面的文件
我正在使用 C# 访问系统上的最新文件,并通过
Environment.SpecialFolder.Recent
Windows 中的最近文件夹复制它们,但只是创建文件实际位置的快捷方式。如何复制快捷方式指向的文件而不是快捷方式本身?
非常感谢您的帮助
I am using C# to access the most recent files on a system and copy them via
Environment.SpecialFolder.Recent
The recent folder in Windows however just creates shortcuts to the actual location of the file. How would one go about copying the file that the shortcut is pointing at as opposed to the shortcut itself?
Many Thanks in advance for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我找到并修改了这段代码,对我有用:
您必须将对
Microsoft Shell Controls And Automation
COM 对象 (Shell32.dll) 的引用添加到项目中才能使其工作。I found and altered this code, works for me:
You have to add a reference to the
Microsoft Shell Controls And Automation
COM object (Shell32.dll) to the project to make this work.这是不久前提出的一个类似的问题,但第一个答案提供了一些代码,这些代码可以执行您想要的操作,从而解析目标文件/文件夹名称。
如何在 c# 中解析 .lnk
从那里,您只需浏览快捷方式列表,解析其链接位置,然后使用 File.Copy(linkPath, copyPath); 完成工作。
This is a similar question that was asked a while ago, but the first answer provides some code that will do what you want as far as resolving the target file / folder name.
How to resolve a .lnk in c#
From there, you would simply go through your list of shortcuts, resolve their linked location, and use
File.Copy(linkPath, copyPath);
to finish the job.也许这个示例代码可以帮助您从.lnk 文件。
Maybe this sample code can help you to get the target link out of a .lnk file.