delphi中获取我的文档文件夹路径

发布于 2024-09-30 05:57:14 字数 766 浏览 0 评论 0原文

我使用以下代码来获取特殊目录

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

痴骨ら 2024-10-07 05:57:14

如果您使用的是最新版本的 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 your uses then use TPath.GetDocumentsPath to get the documents folder.

Check out the Doc Wiki

黑凤梨 2024-10-07 05:57:14

CSIDL_PERSONAL “我的文档”文件夹:

CSIDL_PERSONAL FOLDERID_Documents
版本 6.0。虚拟文件夹
代表“我的文档”桌面
物品。这相当于
CSIDL_MYDOCUMENTS。

6.0 版本之前的版本。该文件
物理上使用的系统目录
存储用户的公共存储库
文件。典型的路径是
C:\Documents and Settings\用户名\My
文件。这应该是
与虚拟My的区别
命名空间中的文档文件夹。到
访问该虚拟文件夹,使用
SHGetFolderLocation,返回
虚拟位置的 ITEMIDLIST,
或参考中描述的技术
管理文件系统。管理文件系统。

请参阅:http://msdn.microsoft.com/en- us/library/bb762494(VS.85).aspx 了解所有可用 CSIDL 常量的列表和说明

CSIDL_PERSONAL is the My Documents folder:

CSIDL_PERSONAL FOLDERID_Documents
Version 6.0. The virtual folder that
represents the My Documents desktop
item. This is equivalent to
CSIDL_MYDOCUMENTS.

Previous to Version 6.0. The file
system directory used to physically
store a user's common repository of
documents. A typical path is
C:\Documents and Settings\username\My
Documents. This should be
distinguished from the virtual My
Documents folder in the namespace. To
access that virtual folder, use
SHGetFolderLocation, which returns the
ITEMIDLIST for the virtual location,
or refer to the technique described in
Managing the File System.Managing the File System.

See: http://msdn.microsoft.com/en-us/library/bb762494(VS.85).aspx for a list and description of all CSIDL constants available

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文