FSUtil.resolve() - shortcut files?

Hi there! o)

I just tried to resolve a path from a "Shortcut.lnk"-file with FSUtil.Resolve(). The docs say, the flag "j" resolves junctions and links to their target folder.
Maybe I understood that wrong, but shortcut files don't seem to work (not a real link I guess?). The function below helps and resolves all lnk-files in a path:

Resolve("D:\\myfolder\\myfolder.lnk\\another.lnk") ==> "C:\\the\\final\\folder\\linked\\to";

function Resolve(path){ var shell = new ActiveXObject("WScript.Shell"); return path.replace(/(.*?\.lnk)(\\|\/|$)/gi, function(m1,m2,m3){ return shell.CreateShortcut(m2).TargetPath+m3;}) }
cya, tbone

1 Like

Kudos for this @tbone. :+1: It works perfectly. Not something I would have worked out for myself in a hurry! :grinning:

Like you, I first tried FSUtil.Resolve() with the "j" flag hoping that it would include resolving shortcuts, despite not promising to do so. Maybe something for the future....

On related matters, the Item object includes is_junction, is_reparse and is_symlink properties. Is there a way of testing whether an item is a shortcut?

You could look at target_type and get the path from target.

https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Scripting/OtherMeta.htm

1 Like

Thanks @lxp. Somehow there is always a way with Opus. :grinning: :+1:

Shortcuts have a .lnk extension which you can test for like any other extension. They are really just normal files, not special filesystem things like symlinks and junctions.