Utilizamos cookies propias y de terceros. [Más información sobre las cookies].
Política de cookies
Proyecto AjpdSoft

· Inicio
· Buscar
· Contactar
· Cookies
· Descargas
· Foros
· Historia
· Nosotros
· Temas
· Top 10
· Trucos
· Tutoriales
· Wiki
Obtener carpetas del sistema - Windows, System, Archivos de programa - Delphi
Lenguaje de programación Borland Delphi


Con estas funciones se podrán obtener las carpetas de: Windows, Sistema, Archivos de programa, archivos comunes y directorio temporal:

...

function obtenerDirectorioWindows : TFileName;
var
  WinDir: array [0..MAX_PATH-1] of char;
begin
  SetString(Result, WinDir, GetWindowsDirectory(WinDir, MAX_PATH));
  if Result = '' then
    raise Exception.Create(SysErrorMessage(GetLastError));
end;

function obtenerDirectorioSistema : TFileName;
var
  SysDir: array [0..MAX_PATH-1] of char;
begin
  SetString(Result, SysDir, GetSystemDirectory(SysDir, MAX_PATH));
  if Result = '' then
    raise Exception.Create(SysErrorMessage(GetLastError));
end;

function obtenerDirectorioProgramas : TFileName;
begin
  with TRegistry.Create do
  try
    RootKey := HKEY_LOCAL_MACHINE;
    OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion', false);
    result := ReadString('ProgramFilesDir');
    CloseKey;
  finally
    free;
  end;
end;

function obtenerDirectorioArchivosComunes : TFileName;
begin
  with TRegistry.Create do
  try
    RootKey := HKEY_LOCAL_MACHINE;
    OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion', false);
    result := ReadString('CommonFilesDir');
    CloseKey;
  finally
    free;
  end;
end;

function obtenerDirectorioTemporal : TFileName;
var
  TmpDir: array [0..MAX_PATH-1] of char;
begin
 try
  SetString(Result, TmpDir, GetTempPath(MAX_PATH, TmpDir));
  if not DirectoryExists(Result) then
   if not CreateDirectory(PChar(Result), nil) then begin
    Result := IncludeTrailingBackslash(obtenerDirectorioWindows) + 'TEMP';
    if not DirectoryExists(Result) then
     if not CreateDirectory(Pointer(Result), nil) then begin
      Result := ExtractFileDrive(Result) + '\TEMP';
      if not DirectoryExists(Result) then
       if not CreateDirectory(Pointer(Result), nil) then begin
        Result := ExtractFileDrive(Result) + '\TMP';
        if not DirectoryExists(Result) then
         if not CreateDirectory(Pointer(Result), nil) then begin
          raise Exception.Create(SysErrorMessage(GetLastError));
         end;
       end;
     end;
   end;
  except
    Result := '';
    raise;
  end;
end;
Ejemplo de utilización:
showmessage('La carpeta de Windows está en: ' + obtenerDirectorioWindows;




Publicado el: 2005-01-04

Visita nuestro nuevo sitio web con programas y contenidos actualizados: Proyecto A