1

I have a file in the folder like "c:\a\abc.mdb"

Sometimes someone could move it to somewhere else and leave a shortcut like "c:\a\abc.mdb.lnk".

In that case when I call IO.File.Exists(@"c:\a\abc.mdb") it still return true. In that case how can I verify if the real file exists, or whether the situation is:

  • abc.mdb exists only
  • abc.mdb.lnk exists only
  • or both of them exists?
Rob
  • 26,989
  • 16
  • 82
  • 98
John Liang
  • 41
  • 5
  • 3
    I am pretty sure `File.Exists` won't resolve a shortcut. You'll need to find some way to read the shortcut and determine the target. – Wai Ha Lee Apr 23 '15 at 22:26
  • I believe the file system (NTFS particularly) is unaware of shortcuts, it's solely the feature of Windows Explorer. The FS is aware of hard/soft links, but it's completely different story. – abatishchev Apr 23 '15 at 22:29
  • Of interest regarding lnk files: http://stackoverflow.com/questions/8660705/how-to-follow-a-lnk-file-programmatically – jdphenix Apr 23 '15 at 22:30
  • This link can be handy: http://www.geektieguy.com/2007/11/19/how-to-parse-special-lnk-files-aka-msi-shortcuts-aka-windows-installer-advertised-shortcuts-using-c/ – Rubens Farias Apr 23 '15 at 22:31
  • 1
    Possible duplicate. Check out this answer: http://stackoverflow.com/a/9882819/3038677 – mycargus Apr 23 '15 at 22:32
  • 1
    I tried this out, but if I have a shortcut at `C:\somefolder\somelink.lnk`, `File.Exists(@"C:\somefolder\somelink")` is still false. Are you sure this works the way you're describing? – Asad Saeeduddin Apr 23 '15 at 22:34

0 Answers0