Ver Mensaje Individual
  #6  
Antiguo 27-08-2022
Avatar de movorack
[movorack] movorack is offline
Miguel A. Valero
 
Registrado: feb 2007
Ubicación: Bogotá - Colombia
Posts: 1.346
Reputación: 20
movorack Va camino a la famamovorack Va camino a la fama
¡Hola, darkbits!

En el registro de windows, las rutas de Desktop, Pesonal, Favorites, etc. Se almacenan en "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"

Aunque, la primera entrada de registro dice esto

"!Do not use this registry key Use the SHGetFolderPath or SHGetKnownFolderPath function instead"

Yo también muevo las ubicaciones de mis documentos, descargas y escritorio a otra unidad. Por lo tanto en esta llave tengo:

Código:
 
Personal=D:\Users\movorack\Documents
Desktop=D:\Users\movorack\Escritorio
My Pictures=D:\Users\movorack\Imágenes
Volviendo a la recomendación de Microsoft. En la VCL, la función SHGetFolderPath se encuentra en la unidad Winapi.SHFolder y con el código a continuación me muestra la ruta de mi escritorio.

Código Delphi [-]
unit Unit1;

interface

uses
  .. SHFolder;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    function GetSpecialFolder(CSIDL: Integer; ForceFolder: Boolean = False): string;
    function getDesktopFolder: string;
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin  
  ShowMessage(getDesktopFolder); //Resultado: D:\Users\movorack\Escritorio
end;

function TForm1.getDesktopFolder: string;
  const
    CSIDL_DESKTOP = $0000;
begin
  Result := GetSpecialFolder(CSIDL_DESKTOP);
end;

function TForm1.GetSpecialFolder(CSIDL: Integer; ForceFolder: Boolean): string;
CONST
  SHGFP_TYPE_CURRENT = 0;
VAR
  i: Integer;
begin
  SetLength(Result, Max_Path);
  if ForceFolder then
    ShGetFolderPath(0, CSIDL OR CSIDL_FLAG_CREATE, 0, 0, PChar(Result))
  else
    ShGetFolderPath(0, CSIDL, 0, 0, PChar(Result));

  i := Pos(#0, Result);
  if i > 0 then
    SetLength(Result, pred(i));

  Result := IncludeTrailingPathDelimiter(Result);
end;

end.
__________________
Buena caza y buen remar... http://mivaler.blogspot.com
Responder Con Cita