Question:
I want to get Windows System Directory, can you show me?
Answer:
Sure, please check this example below. Not only to get Windows System Directory but also Temporary Directory and Windows Directory.
{ 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;
Subscribe to:
Post Comments (Atom)
the problem of data corruption in the files of specified format can be fixed by the fix broken pdf file utility
marc jacobs, soccer shoes, abercrombie and fitch, hollister, asics running shoes, canada goose, ugg boots, nfl jerseys, reebok outlet, herve leger, ugg, north face outlet, mont blanc, longchamp, insanity workout, canada goose uk, chi flat iron, babyliss pro, ugg pas cher, ugg australia, canada goose jackets, mcm handbags, canada goose, wedding dresses, new balance shoes, mac cosmetics, soccer jerseys, celine handbags, birkin bag, p90x, ferragamo shoes, valentino shoes, nike huarache, beats by dre, ghd, instyler, jimmy choo outlet, lululemon outlet, bottega veneta, canada goose, rolex watches, canada goose outlet, vans shoes, nike roshe run, moncler, ugg boots, north face jackets, uggs outlet, giuseppe zanotti
chenlina20160713
michael kors handbags
louis vuitton outlet
oakley sunglasses
nike trainers men
cheap jordan shoes
true religion sale
nike free run
louis vuitton
coach canada
coach outlet
insanity workout
nike outlet
supra shoes
kate spade handbags
louis vuitton outlet
jordan 3 white cenment
gucci outlet
ray ban wayfarer
ray ban sunglasses
ray ban sunglasses
michael kors outlet
louis vuitton handbags
coach outlet store online clearances
adidas outlet
rolex watches
coach outlet
christian louboutin sale
michael kors outlet
hollister clothing
jordan 4 toro
kobe 9
jordan retro 11
coach outlet
ralph lauren polo
tiffany outlet
louis vuitton outlet
air jordan pas cher
kate spade handbags
gucci handbags
cheap ray ban sunglasses
as