Fórum Como verificar se arquivo texto já está aberto? #447214
30/06/2013
0
Será que alguém poderia me dar uma ajudinha nisso?
Grato e aguardo qualquer orientação.
M. C.
Curtir tópico
+ 0Posts
09/07/2013
M. C.
Gostei + 0
13/07/2013
Adalberto Brasaca
function IsFileInUse(fName : string) : boolean;
var //fNAME é o caminho com o nome do arquivo a ser testado se está em uso.
HFileRes : HFILE;
begin
Result := false;
if not FileExists(fName) then exit;
HFileRes := CreateFile(pchar(fName), GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
Result := (HFileRes = INVALID_HANDLE_VALUE);
end;
Se a função retornar True, o arquivo está em uso. Caso retorne False, não está.
Gostei + 0
20/07/2013
M. C.
function IsFileInUse(fName : string) : boolean;
var //fNAME é o caminho com o nome do arquivo a ser testado se está em uso.
HFileRes : HFILE;
begin
Result := false;
if not FileExists(fName) then exit;
HFileRes := CreateFile(pchar(fName), GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
Result := (HFileRes = INVALID_HANDLE_VALUE);
end;
Se a função retornar True, o arquivo está em uso. Caso retorne False, não está.
Olá,
Não consegui resolver não.
Se não me falha a memória, já tentei algo muito parecido com essa sua função.
Vou ver se com a sua ajuda a coisa aqui dá certo.
Grato pela sua atenção.
Gostei + 0
26/07/2013
Alessandro Yamasaki
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
Clique aqui para fazer login e interagir na Comunidade :)