Delphi-Quellcode:
function MakeFile(const AFilename: string; const AOverwrite: Boolean = False; const AShowError: Boolean = False): Boolean;
const
INVALID_HANDLE_VALUE = THandle(-1);
var
h: THandle;
begin
Result := False;
if (AFilename = '') then
Exit;
if (AOverwrite and FileExists(AFilename)) then
if (not DeleteFile(AFilename)) then
begin
if AShowError then
ShowMessage('File deletion for "' + AFilename + '" failed.');
Exit;
end;
if (not FileExists(AFilename)) then
begin
h := FileCreate(AFilename);
if (h = INVALID_HANDLE_VALUE) then
begin
if AShowError then
ShowMessage('File creation for "' + AFilename + '" failed.');
Exit;
end
else
begin
FileClose(h);
Result := True;
end;
end
else
Result := True;
end;
Eine weitere Möglichkeit.
//Edit, methode ist nun eine function und man könnte es als "if makefile('blabla.bla')" nutzen