I think it would be greate if the “sys” module would provide the paths of the “special folders”, analogous to “sys.env”.
I used the following code for one of my projects:
-- Gets the special folder full path.
local function getSpecialFolderPath(csidl)
local WshShell = sys.COM("Shell.Application")
return WshShell:NameSpace(csidl).self.path
end
-- Constants identify special folders.
local CSIDL = {
appdata = 0x001a,
commonappdata = 0x0023,
commondesktop = 0x0019,
commonprograms = 0x0017,
commonstartmenu = 0x0016,
commonstartup = 0x0018,
desktop = 0x0010,
documents = 0x0005,
localappdata = 0x001c,
music = 0x000d,
pictures = 0x0027,
profile = 0x0028,
programfiles = 0x026,
programfilesx86 = 0x002a,
programs = 0x0002,
recent = 0x0008,
sendto = 0x0009,
startmenu = 0x000b,
startup = 0x0007,
system = 0x0025,
systemx86 = 0x0029,
videos = 0x000e,
windows = 0x0024,
}
-- Get a proxy table representing special folders.
sysextension.specialfolders = {
desktop = getSpecialFolderPath(CSIDL.desktop),
documents = getSpecialFolderPath(CSIDL.documents),
music = getSpecialFolderPath(CSIDL.music),
pictures = getSpecialFolderPath(CSIDL.pictures),
programs = getSpecialFolderPath(CSIDL.programs),
startmenu = getSpecialFolderPath(CSIDL.startmenu),
videos = getSpecialFolderPath(CSIDL.videos),
}