delphi中获取我的文档文件夹路径
我使用以下代码来获取特殊目录
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;
现在我想获取我的文档路径 所以我用 mydocfolderpath := string(FBuf) + '\Documents' 我认为它效果很好 但我怀疑这是所有 Windows PC 上的 mydocuments 路径(个人文件夹/文档)用户是否可以更改此结构并将我的文档文件夹放在其他位置(例如:c:\documents) 如果用户更改路径给我一个正确的方法,我想知道 mydocuments 文件夹的名称是什么(我的文档或文档)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用的是最新版本的 Delphi(XE5 或更高版本),那么您可以使用新的平台无关类。基本上在您的
uses
中包含System.IOUtils
,然后使用TPath.GetDocumentsPath
来获取文档文件夹。查看Doc Wiki
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 youruses
then useTPath.GetDocumentsPath
to get the documents folder.Check out the Doc Wiki
CSIDL_PERSONAL 是“我的文档”文件夹:
请参阅:http://msdn.microsoft.com/en- us/library/bb762494(VS.85).aspx 了解所有可用 CSIDL 常量的列表和说明
CSIDL_PERSONAL is the My Documents folder:
See: http://msdn.microsoft.com/en-us/library/bb762494(VS.85).aspx for a list and description of all CSIDL constants available