【问题标题】:How to know if a *.lnk file link to something or not如何知道 *.lnk 文件是否链接到某个东西
【发布时间】:2013-02-10 11:46:58
【问题描述】:

如何知道 *.lnk 文件是否链接到某个东西。如何在 C# 中实现这一点?

【问题讨论】:

  • 也许检查文件是否存在于链接属性路径上?
  • stackoverflow.com/questions/139010/… 然后使用相应的file.exists来查看是否存在。
  • 一个链接总是链接到某个东西,你的意思是要检查那个东西当前是否可以访问?
  • 我想知道一个 lnk 文件是否链接到某个东西。如果没有,我想删除它们。

标签: visual-studio-2010 c#-4.0


【解决方案1】:
  1. 获取Link Target Getting specific file attributes
  2. 检查来自Link Target Path 的文件是否存在,使用File.Exists
class Program
{
    [STAThread]
    static void Main()
    {
        List<string> arrHeaders = new List<string>();

        Shell32.Shell shell = new Shell32.Shell();
        Shell32.Folder objFolder;

        objFolder = shell.NameSpace(@"D:\shortcuts");

        for (int i = 0; i < short.MaxValue; i++)
        {
            string header = objFolder.GetDetailsOf(null, i);
            if (String.IsNullOrEmpty(header))
                break;
            arrHeaders.Add(header);
        }

        foreach (Shell32.FolderItem2 item in objFolder.Items())
        {
            for (int i = 0; i < arrHeaders.Count; i++)
            {
                //Console.WriteLine("{0}\t{1}: {2}", i, arrHeaders[i], objFolder.GetDetailsOf(item, i));
                if (arrHeaders[i] == "Link target")
                {
                    var getPath = objFolder.GetDetailsOf(item, i);
                    Console.WriteLine("{0}", getPath);
                    if (File.Exists(getPath))
                    {
                        Console.WriteLine("The file exists.");
                    }
                    else
                    {
                        Console.WriteLine("File not exist");
                        //Do stuff to delete
                    }
                }
            }
        }
        Console.ReadLine();
    }
}

【讨论】:

    猜你喜欢
    • 2012-12-02
    • 2022-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多