如何知道* .lnk文件是否链接到某个东西。我怎样才能在C#中实现这一目标?
答案 0 :(得分:0)
Link Target
Getting specific file attributes Link Target Path
中的文件(如果存在)
醇>
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(); } }