Delphi Source Code
Search engine
HOME Components Tutorials Add Trick Links Contacts
ActiveX Components Database Files Forms Graphic Internet/Lan Math Miscellaneous Multimedia Printing Strings System Information Windows

Delphi source code for System Information >> Get windows, system, temporary directory


Category: System Information
Title: Get windows, system, temporary directory
Date added: 15.03.2006
Hits: 52048


{ Getting the Windows Directory }

function GetWinDir: string;
var
  dir: array [0..MAX_PATH] of Char;
begin
  GetWindowsDirectory(dir, MAX_PATH);
  Result := StrPas(dir);
end;

function WindowsDirectory: string;
var
  WinDir: PChar;
begin
  WinDir := StrAlloc(MAX_PATH);
  GetWindowsDirectory(WinDir, MAX_PATH);
  Result := string(WinDir);
  if Result[Length(Result)] <> '\' then
    Result := Result + '\';
  StrDispose(WinDir);
end;

function GetWindowsDirectory(var S: String): Boolean;
var
  Len: Integer;
begin
  Len := Windows.GetWindowsDirectory(nil, 0);
  if Len > 0 then
  begin
    SetLength(S, Len);
    Len := Windows.GetWindowsDirectory(PChar(S), Len);
    SetLength(S, Len);
    Result := Len > 0;
  end else
    Result := False;
end;
{ Getting the System Directory }

function SystemDir: string;
var
  dir: array [0..MAX_PATH] of Char;
begin
  GetSystemDirectory(dir, MAX_PATH);
  Result := StrPas(dir);
end;

function SystemDirectory: string;
var
  SysDir: PChar;
begin
  SysDir := StrAlloc(MAX_PATH);
  GetSystemDirectory(SysDir, MAX_PATH);
  Result := string(SysDir);
  if Result[Length(Result)] <> '\' then
    Result := Result + '\';
  StrDispose(SysDir);
end;

function GetSystemDirectory(var S: String): Boolean;
var
  Len: Integer;
begin
  Len := Windows.GetSystemDirectory(nil, 0);
  if Len > 0 then
  begin
    SetLength(S, Len);
    Len := Windows.GetSystemDirectory(PChar(S), Len);
    SetLength(S, Len);
    Result := Len > 0;
  end else
    Result := False;
end;
{ Getting the Temporary Directory }

function GetTempDir: string;
var
  Buffer: array[0..MAX_PATH] of Char;
begin
  GetTempPath(SizeOf(Buffer) - 1, Buffer);
  Result := StrPas(Buffer);
end;

function GetTempPath: string;
var
  TmpDir: PChar;
begin
  TmpDir := StrAlloc(MAX_PATH);
  GetTempPath(TmpDir, MAX_PATH);
  Result := string(TmpDir);
  if Result[Length(Result)] <> '\' then
    Result := Result + '\';
  StrDispose(TmpDir);
end;

function GetTempPath(var S: String): Boolean;
var
  Len: Integer;
begin
  Len := Windows.GetTempPath(0, nil);
  if Len > 0 then
  begin
    SetLength(S, Len);
    Len := Windows.GetTempPath(Len, PChar(S));
    SetLength(S, Len);
    Result := Len > 0;
  end else
    Result := False;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  label1.Caption := GetWinDir;
  label2.Caption := GetSysDir;
  label3.Caption := GetTempDir;
end;

Related Delphi Source Code:
Delphi Tricks
Delphi Tricks
For any problems or recommendations about Delphi Tricks site, please

feel free to contact us on that e-mail: support@delphitricks.com.
If you want to advertise on the site use that e-mail: advertise@delphitricks.com.

You can freely use or modify these Delphi source codes for non-commercial use. We are not responsible of any damages that can be caused by the utilisation of that source codes.

Copyright © 2006-2010 AVSoftware Company. All rights reserved.
Hide IP tricks