Fórum Verificar se arquivo TXT está em uso #421331
09/08/2012
0
Preciso verificar se o arquivo txt está sendo usado por outros usuários ou não.
Aguardo
Huelbert Oliveira
Curtir tópico
+ 0Posts
09/08/2012
Romulo Contro
Gostei + 0
09/08/2012
Junior Miranda
[]´s
Gostei + 0
09/08/2012
Deivison Melo
Tente utilizar a função abaixo:
/*inicio*/
function IsFileInUse(FileName: TFileName): 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;
/*fim*/
Exemplo de uso:
/*inicio*/
procedure TForm1.Button1Click(Sender: TObject);
begin
if IsFileInUse(c:\Programs\delphi6\bin\delphi32.exe) then
ShowMessage(File is in use.);
else
ShowMessage(File not in use.);
end;
/*fim*/
Gostei + 0
09/08/2012
Huelbert Oliveira
Gostei + 0
09/08/2012
Huelbert Oliveira
Excluindo também não deu certo, ele deleta mesmo utilizando.
Se fosse um EXE era só utilizar a função acima, mas como é um TXT até agora não encontrei uma solução.
Gostei + 0
10/08/2012
Romulo Contro
to acompanhando o tópico, pq agora fiquei curioso também, mas não tenho idéia :S
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)