I'm trying to determine if the path targeted by a shortcut on Windows is a folder. Let's say I have a test.lnk file on my Desktop which points to the R:\test folder located on a network location. If I also have a shortcut that points to the R:\test.zip archive, I would not want this file to appear in my view.
I currently have the following code which correctly achieves this requirement:
Shell variable = (Shell)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("13709620-C279-11CE-A49E-444553540000")));
FolderItem variable1 = variable.NameSpace(directoryName).ParseName(fileName);
if (variable1 != null)
{
var shellObject = (ShellLinkObject)variable1.GetLink;
var isShortcutAFolder = shellObject.Target.IsFolder && shellObject.Target.Type == "File folder";
// ...
}
The issue with this approach is that the shellObject.Target.Type property is of type string and its value depends on the language the user has on their machine. The reason I check this property in addition to the IsFolder property of the Target is that archive files (such as .zip and .rar) also have their IsFolder value as true and I do not wish to show such files as directories.
With this said, is there another property I can use of the FolderItem object or some cast that I can make to determine if the target path is actually a file folder?
I do not wish to use the File.GetAttributes or Directory.Exists methods as these result in degraded performance if the network location is offline or inaccessible.