Autor Beitrag
tartare
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 89

Win XP SP2, WIN Vista Home Professional
Delphi 7/2009, C#, C++(VS 2005 Express)
BeitragVerfasst: Mo 01.05.06 20:38 
Hallo, ich schreibe ein Programm, in dem ich alle Temp-Dateien löschen will, die nicht in Benutzung sind, wie kann ich nun feststellen ob eine in benutzung ist?
Oder gibt es vielleicht schon Prozeduren dafür? Bin Dankbar für jede Hilfe.
mfg Tartare


Moderiert von user profile iconraziel: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Di 09.05.2006 um 16:12

_________________
Ich leb in meiner eigenen Welt, aber das is ok, da kennt man mich.
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Di 09.05.06 13:00 
Die folgende Funktion prüft, ob eine Datei in Benutzung ist. Als Parameter muss der pfad+Dateiname der Datei übergeben werden. Gibt die Funktion True zurück ist die Datei in Benutzung

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
function IsFileInUse(Path: string): boolean;
var hFile: THandle;
begin
  Result := False;
    if not FileExists(Path) then Exit;

    hFile := CreateFile(pchar(Path), GENERIC_READ or GENERIC_WRITE or GENERIC_EXECUTE,
                      0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
    Result := hFile = INVALID_HANDLE_VALUE;
    if not Result then CloseHandle(hFile);

end;


Aufgerufen werden kann die Funktion beispielsweise so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.Button1Click(Sender: TObject);
begin
  if IsFileInUse(Application.Exename) then
        Showmessage('Die Datei ist in Benutzung');
end;


lg
Stefan

Moderiert von user profile iconGausi: Quote- durch Delphi-Tags ersetzt

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
tartare Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 89

Win XP SP2, WIN Vista Home Professional
Delphi 7/2009, C#, C++(VS 2005 Express)
BeitragVerfasst: Di 09.05.06 13:48 
Dankeschööön für die Hilfe...

_________________
Ich leb in meiner eigenen Welt, aber das is ok, da kennt man mich.