Looks like csidl folder 23 gets the path youâd needâŚ
q: pathname of csidl folder 23
A: C:\ProgramData\Microsoft\Windows\Start Menu\Programs
Lots of different ways to do it though. You could take advantage of the fact that Windows 10 uses symlinks under the âAll Usersâ profile, so you can reference the folder as either path (and use the Windows 7 style path alone). Substituting your query for a folder that exists on my start menu, I can refer to it either wayâŚ
q: folders ("Microsoft\Windows\Start Menu\Programs\Visual Studio 2017\Visual Studio Tools";"Start Menu\Programs\Visual Studio 2017\Visual Studio Tools") of folders (value of variable "ALLUSERSPROFILE" of environment)
A: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2017\Visual Studio Tools
A: C:\ProgramData\Start Menu\Programs\Visual Studio 2017\Visual Studio Tools
T: 0.362 ms
I: plural folder
As usual, there are several ways to do it. Suppose you were looking for files in some other set of folders that didnât have a neat, direct mapping to csidl folders? The original statement can still be simplified (again, using a file that exists on my system instead):
q: (if exists files "Debuggable Package Manager.lnk" whose (sha1 of it = "e018eed217fb176c1241454b49b81139fda41d10") of it then "2017" else if exists files "Debuggable Package Manager.lnk" whose (sha1 of it = "xxxxx") of it then "2016" else "None") of folders ("Microsoft\Windows\Start Menu\Programs\Visual Studio 2017\Visual Studio Tools";"Start Menu\Programs\Visual Studio 2017\Visual Studio Tools") of folders (value of variable "ALLUSERSPROFILE" of environment)
A: 2017
A: 2017
T: 0.661 ms
I: plural string
I get a duplicate entry because I can actually find the file at both paths. If the file doesnât exist, but the path does, Iâd get ânoneâ. If the folder didnât exist at all, Iâd get an empty result.
Maybe I donât want the duplicatesâŚI could substitute prefix âunique values ofâ. What if an empty result isnât sufficient, and I really need the explicit ânoneâ result? I can load the results in a set and check the size of it, to handle both cases.
q: (if size of it = 0 then "none" else elements of it ) of set of (if exists files "Debuggable Package Manager.lnk" whose (sha1 of it = "e018eed217fb176c1241454b49b81139fda41d10") of it then "2017" else if exists files "Debuggable Package Manager.lnk" whose (sha1 of it = "xxxxx") of it then "2016" else "None") of folders ("Microsoft\Windows\Start Menu\Programs\Visual Studio 2017\Visual Studio Tools";"Start Menu\Programs\Visual Studio 2017\Visual Studio Tools") of folders (value of variable "ALLUSERSPROFILE" of environment)
A: 2017
T: 0.727 ms
I: plural string
In fact, taking advantage of the fact that a missing folder causes the ( if ) block to not evaluate at all, and an empty result leads a set of size 0 and a result of ânoneâ, we can shorten the if block a bit, moving the filename out of the block (if it doesnât exist, our set size is still 0 and we still get the ânoneâ):
q: (if size of it = 0 then "none" else elements of it ) of set of (if sha1 of it = "e018eed217fb176c1241454b49b81139fda41d10" then "2017" else if sha1 of it = "xxxxx" then "2016" else nothing) of files "Debuggable Package Manager.lnk" of folders ("Microsoft\Windows\Start Menu\Programs\Visual Studio 2017\Visual Studio Tools";"Start Menu\Programs\Visual Studio 2017\Visual Studio Tools") of folders (value of variable "ALLUSERSPROFILE" of environment)
A: 2017
T: 0.697 ms
I: plural string
Another option is to remove the â ( if ) â block entirely, and build a whose() clause to compare the file sha1 to a list of known sha1 values, and return only the version/description matching that sha1; this makes it a bit easier to add more versions later by preventing the if/then/elseif/then/else from grown too muchâŚthis is actually the form I think Iâd prefer, now that I look at it a little more closely, as itâs easier to extend.
q: (if size of it = 0 then "none" else elements of it ) of set of items 0 of (("2017", "e018eed217fb176c1241454b49b81139fda41d10", it); ("Other Version", "xxxxx", it )) whose (item 2 of it = item 1 of it) of sha1s of files "Debuggable Package Manager.lnk" of folders ("Microsoft\Windows\Start Menu\Programs\Visual Studio 2017\Visual Studio Tools";"Start Menu\Programs\Visual Studio 2017\Visual Studio Tools") of folders (value of variable "ALLUSERSPROFILE" of environment)
A: 2017
T: 0.715 ms
I: plural string