如何知道 *.lnk 文件是否链接到某个东西。我怎样才能在 C# 中实现这一点?
user2058540
问问题
329 次
1 回答
0
- Get the
Link Target
Getting specific file attributes - Check the file from
Link Target Path
if exist using the 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(); } }
于 2013-02-10T23:24:50.743 回答