本文介绍了获取快捷方式文件夹的目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让一个快捷方式文件夹的目录目标是什么?我已经到处寻找,只找到快捷方式文件的目标。

How do you get the directory target of a shortcut folder? I've search everywhere and only finds target of shortcut file.

推荐答案

我想你会需要使用COM和添加引用微软壳牌控制和自动化,为的:

I think you will need to use COM and add a reference to "Microsoft Shell Control And Automation", as described in this blog post:

下面是一个使用该处提供的code的例子:

Here's an example using the code provided there:

namespace Shortcut
{
    using System;
    using System.Diagnostics;
    using System.IO;
    using Shell32;

    class Program
    {
        public static string GetShortcutTargetFile(string shortcutFilename)
        {
            string pathOnly = System.IO.Path.GetDirectoryName(shortcutFilename);
            string filenameOnly = System.IO.Path.GetFileName(shortcutFilename);

            Shell shell = new Shell();
            Folder folder = shell.NameSpace(pathOnly);
            FolderItem folderItem = folder.ParseName(filenameOnly);
            if (folderItem != null)
            {
                Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
                return link.Path;
            }

            return string.Empty;
        }

        static void Main(string[] args)
        {
            const string path = @"C:\link to foobar.lnk";
            Console.WriteLine(GetShortcutTargetFile(path));
        }
    }
}

这篇关于获取快捷方式文件夹的目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 22:52