i use the following code to get special directories
uses
ActiveX, ShlObj;
{...}
procedure TForm1.Button1Click(Sender: TObject);
// Replace CSIDL_HISTORY with the constants below
var
Allocator: IMalloc;
SpecialDir: PItemIdList;
FBuf: array[0..MAX_PATH] of Char;
PerDir: string;
begin
if SHGetMalloc(Allocator) = NOERROR then
begin
SHGetSpecialFolderLocation(Form1.Handle, CSIDL_PERSONAL, SpecialDir);
SHGetPathFromIDList(SpecialDir, @FBuf[0]);
Allocator.Free(SpecialDir);
ShowMessage(string(FBuf));
end;
end;
And now i want to get the my documents path so i use mydocfolderpath := string(FBuf) + '\Documents' and i think it works well but my doubt is this the mydocuments path on all windows PCs (personalfolder/documents) can the user change this stucture and make my documents folder anywhare else (eg: c:\documents) if the user an change the path give me a proper way and i like to know what is the name of mydocuments folder (My Documents or Documents)
If you are using a recent version of Delphi (XE5 or greater) then you can use the new platform agnostic classes. Basically include System.IOUtils
in your uses
then use TPath.GetDocumentsPath
to get the documents folder.
Check out the Doc Wiki
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With