Autor Beitrag
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Sa 08.07.06 11:31 
Hallo!

Ich würde gerne testen, ob eine Datei beschreibbar ist (also nicht durch einen anderen Prozess schon beschrieben/in Benutzung ist), ohne, dass ich etwa sowas machen muss:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
try
  FileStream:=TFileStream.Create({der Dateiname}, fmCreate);
except
  showmessage('geht net...');
end;


Gibts dazu nich noch ne einfachere (API?) Funktion?

Gruß alias5000

_________________
Programmers never die, they just GOSUB without RETURN
alias5000 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Sa 08.07.06 12:42 
So, nach etwas mehr Internetrecherche hab ich mein Problem mal wieder selbst erledigt (warum bekomm ich hier eigetlich immer so wenig Antworten auf meine Fragen?? :evil: )

Dieser Code reicht mir IMHO:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
function IsFileInUse(const FileName: String): Boolean;
var
  HFileRes : HFILE;
begin
  Result := false;
  if not FileExists(FileName) then exit;
  HFileRes := CreateFile(PChar(FileName), GENERIC_READ or GENERIC_WRITE,0, nil, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, 0);
  Result := (HFileRes = INVALID_HANDLE_VALUE);
  if not Result then CloseHandle(HFileRes);
end;


Quelle: Delphi-Praxis

_________________
Programmers never die, they just GOSUB without RETURN
Spaceguide
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 552


(D3/D7/D8) Prof.
BeitragVerfasst: Sa 08.07.06 12:59 
user profile iconalias5000 hat folgendes geschrieben:
So, nach etwas mehr Internetrecherche hab ich mein Problem mal wieder selbst erledigt (warum bekomm ich hier eigetlich immer so wenig Antworten auf meine Fragen??


Das Problem kenne ich. Immer wenn's ans Eingemachte geht ist großes Schweigen im Wald. Aber lange gewartet hast du ja nicht.

Hast du mal überprüft, ob dein Code die eventuell bereits vorhandene und nicht schreibgeschützte Datei beim Überprüfen auch nicht zerstört?
alias5000 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Sa 08.07.06 13:04 
Bin grad dabei. Hab jetzt halt net lange gewartet, weil ich selber was gefunden hab, na egal. Ich glaub, wenn sich solche Sachen ab und zu mal wiederholen, regt man sich einfach viel zu schnell auf :wink:

Also ich teste mal n bissl, bis dann

EDIT: also, wie vermutet, es geht, ohne dass sie schreibt. Mit CreateFile schreibe ich ja auch noch nicht :wink:

Gruß alias5000

_________________
Programmers never die, they just GOSUB without RETURN
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 08.07.06 13:12 
Der Klassiker schlecht hin: luckie-online.de/Developer/Delphi/Sonstiges/CheckFileAccess.html

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.