我使用以下代码来获取特殊目录
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;
Run Code Online (Sandbox Code Playgroud)
现在我想得到我的文档路径,所以我使用mydocfolderpath:= string(FBuf)+'\ Documents',我认为它运作良好但我怀疑这是所有Windows PC(个人文件夹/文件)上的mydocuments路径可以用户更改此结构并使我的文档文件夹anywhare else(例如:c:\ documents)如果用户更改路径给我一个正确的方式,我想知道mydocuments文件夹的名称是什么(我的文档或文档)
Mar*_*ema 15
CSIDL_PERSONAL 是我的文档文件夹:
CSIDL_PERSONAL FOLDERID_Documents版本6.0.表示"我的文档"桌面项的虚拟文件夹.这相当于CSIDL_MYDOCUMENTS.
6.0版之前的版本.用于物理存储用户的公共文档存储库的文件系统目录.典型的路径是C:\ Documents and Settings\username\My Documents.这应该与命名空间中的虚拟My Documents文件夹区分开来.要访问该虚拟文件夹,请使用SHGetFolderLocation,它返回虚拟位置的ITEMIDLIST,或者参考管理文件系统中所述的技术.管理文件系统.
请参阅:http://msdn.microsoft.com/en-us/library/bb762494(VS.85).aspx获取所有可用CSIDL常量的列表和说明