I'm building an image thumbnail cache system, and one of the main things I need it to do is basically ask Windows for the best place to store my permanent cached files. I've seen many good ways of getting temp directories, but I need a permanent cache location. How do I get this from Windows?
NOTE
This system will actually be working as a Windows Service (or a thread) running in the background - as well as many applications reading from this cache. It needs to be on a global level, and not per windows user.
First you need to find out where to store your data. At MSDN is a list of the old CSIDL constants. To obtain a path from a CSIDL constant, use the SHGetFolderPath
function like this (uses ShFolder
):
procedure TForm1.Button1Click(Sender: TObject);
var
path: array[0..MAX_PATH] of char;
begin
SHGetFolderPath(0, CSIDL_COMMON_APPDATA, 0, SHGFP_TYPE_CURRENT, @path);
ShowMessage(path);
end;