Delphi - 使用 SHGetSpecialFolderPath 获取我的下载文件夹

Delphi - Use SHGetSpecialFolderPath to get My Download folder

我正在使用 SHGetSpecialFolderPath 通过 Delphi 检索一些 Windows 特殊文件夹 7. 下面是一些代码示例:

const
  CSIDL_DESKTOP    = [=11=]00;
  CSIDL_PERSONAL   = [=11=]05;
  CSIDL_MYPICTURES = [=11=]27;
  CSIDL_MYMUSIC    = [=11=]0d;
  CSIDL_MYVIDEO    = [=11=]0e;
  CSIDL_WINDOWS    = [=11=]24;
  CSIDL_SYSTEM     = [=11=]25;

function GetSpecialFolderPath(Folder: Integer; ForceDir: Boolean): string;
// Uses ShlObj
var
  Path: array [0..255] of char;
begin
  SHGetSpecialFolderPath(0, @Path[0], Folder, ForceDir);
  Result := Path;
end;

edtFolder.Text := GetSpecialFolderPath(CSIDL_DESKTOP, False);

如何使用这种方法获取 "Downloads" 文件夹?

您无法通过 API 获取该目录。它早于任何 OS 指定的下载文件夹。

您需要使用更新的概念“known folders" with the flag FOLDERID_Downloads instead. How to do that has already been answered elsewhere on Stack Overflow