zoukankan      html  css  js  c++  java
  • [函数] Delphi FMX Windows 取得下载 Downloads 目录

    在 Firemonkey 提供了一个跨平台的函数 TPath.GetDownloadsPath 来取得该平台的下载目录,但是非常奇怪的是,在 Windows 平台下,取得的下载目录确是:

    C:Users<username>AppDataLocal (官方文件

    而不是

    C:Users<username>Downloads

    也许 EMB 想的是 App 沙箱做法,但如果想要取得 C:Users<username>Downloads 这个目录该如何做呢?

    可以扩展 TPath 功能,参考如下:

    unit System.IOUtils.Helper;
    
    interface
    
    uses
      {$IFDEF MSWINDOWS}
      Winapi.Windows,
      Winapi.ShlObj,
      Winapi.KnownFolders,
      {$ENDIF}
    
      System.IOUtils;
    
    type
      TPathHelper = record helper for TPath
        class function GetWinDownloadsPath: string; static;
      end;
    
    implementation
    
    class function TPathHelper.GetWinDownloadsPath: string;
    {$IFDEF MSWINDOWS}
    var Path: PWideChar;
    begin
         if Succeeded(SHGetKnownFolderPath(FOLDERID_Downloads, 0, 0, Path)) then
              Result := String(Path)
         else Result := '';
    end;
    {$ELSE}
    begin
         Result := '';
    end;
    {$ENDIF}
    
    end.

    使用方法:

    uses System.IOUtils.Helper;
    
    var DownloadPsth: String;
    begin
      DownloadPath := TPath.GetWinDownloadsPath;
    end;
  • 相关阅读:
    Ant
    责任链模式
    日志logback
    知识点
    三个实例演示 Java Thread Dump 日志分析
    IDEA运行编译后配置文件无法找到,或配置文件修改后无效的问题
    IDEA创建MAVEN WEB工程
    多线程源码分析ThreadPoolExecutor
    解决
    微博关系服务与Redis的故事
  • 原文地址:https://www.cnblogs.com/onechen/p/5739816.html
Copyright © 2011-2022 走看看