Tempディレクトリを取得する
テンポラリディレクトリを取得するには GetTempPath APIを使用します。また、テンポラリファイルはユニークな名前にしたい場合があります。その場合は GetTempFileName APIを使用します。
| ■ テンポラリディレクトリを取得する例 |
procedure TForm1.Button1Click(Sender: TObject);
var
chrTempPath : array [0..MAX_PATH] of char;
begin
GetTempPath(sizeof(chrTempPath),chrTempPath);
ShowMessage (chrTempPath); {¥つき}
end;
|
| ■ テンポラリファイルにユニークな名前をつける例 |
procedure TForm1.Button1Click(Sender: TObject);
var
strTempPath : string;
strPrefix : string;
chrTempFileName : array [0..MAX_PATH] of char;
begin
strTempPath := '.'; { ピリオドはカレントディレクトリ }
strPrefix := 'YPT'; { テンポラリファイルの頭につく文字 }
GetTempFileName(PChar(strTempPath),PChar(strPrefix), 0,chrTempFileName);
ShowMessage (chrTempFileName);
end;
|