Fórum Lendo arquivo de texto #457012
30/09/2013
0
procedure TForm1.btnOkClick(Sender: TObject);
var
arq: TextFile; { declarando a variável "arq" do tipo arquivo texto }
linha: string;
o, d: PAnsiChar;
begin
AssignFile(arq, edtRecebeCaminho.Text);
{$I-} // desativa a diretiva de Input
Reset(arq); // [ 3 ] Abre o arquivo texto para leitura
{$I+} // ativa a diretiva de Input
// verifica o resultado da operação de abertura
if(IOResult <> 0) then
begin
while (not eof(arq)) do
begin
readln(arq, linha); // [ 6 ] Lê uma linha do arquivo
end;
end;
//se achar o código 124
if (linha = '124') then
begin
//ele ira receber o caminho, o destino e vai mover o meu arquivo para a pasta desejada
o := PCHAR(edtRecebeCaminho.Text + edtDestino.Text + '*.txt');
d := PCHAR(edtDestino.Text + edtRecebeCaminho.Text + '*.txt');
MoveFile(o,d);
CloseFile(arq); // [ 8 ] Fecha o arquivo texto aberto
end
else
showmessage('Não existem erros de : Cupom já registrado no sistema !!!');
end;
Lucas Garcia
Curtir tópico
+ 0Posts
30/09/2013
Ricardo Rodrigues
Gostei + 0
30/09/2013
Lucas Garcia
Gostei + 0
30/09/2013
Ricardo Rodrigues
Gostei + 0
30/09/2013
Lucas Garcia
Gostei + 0
30/09/2013
Ricardo Rodrigues
procedure TForm1.BitBtn9Click(Sender: TObject);
var
Arq : TextFile;
Texto : string;
Txt : TStringList;
begin
memo1.clear;
Txt := TStringList.Create;
Txt.Delimiter := ';';
try
Screen.Cursor := crHourGlass;
AssignFile(Arq,'Caminho do arquivo');
Reset(Arq);
if not EOF(Arq) then
repeat
ReadLn(Arq, Texto);
texto := StringReplace(StringReplace(Texto,' ','*',[rfReplaceAll]),'#32',' ',[rfReplaceAll]);
Txt.DelimitedText := Texto;
Memo1.Lines.Add(' insert into grupo (cod_empr, cod_grup, descricao, sigla) values ('+
'1,'+
txt[0]+','+
''''+copy(stringreplace(Txt[1],'*',' ',[rfReplaceAll]),1,40)+''','+
''''+copy(stringreplace(Txt[3],'*',' ',[rfReplaceAll]),1,3)+''');');
Memo1.Lines.Add(' ');
until EOF(Arq);
finally
Closefile(Arq);
Screen.Cursor := crDefault;
end;
FreeAndNil(Txt);
end;
Gostei + 0
30/09/2013
Lucas Garcia
Gostei + 0
30/09/2013
Marcos Saffran
tente o AnsiPos:
if AnsiPos('124', linha) > 0 then
begin
ShowMessage('Encontrou 124, na posição : ' + IntToStr(AnsiPos('124', linha); //aqui coloque o código de encontrado
end
else
begin
ShowMessage('Não encontrou 124'); //aqui coloque o código de não encontrado.
end;Gostei + 0
30/09/2013
Marcos Saffran
if(IOResult <> 0) then
begin
while (not eof(arq)) do
begin
readln(arq, linha); // [ 6 ] Lê uma linha do arquivo
end;
end;
//se achar o código 124
if (linha = '124') then
begindo jeito que está o seu código o comando while vai ler o arquivo todo, a última linha do arquivo é que será salva na variável linha, recomendo que coloque a verificação do conteúdo dentro do while e cancele-o se for encontrado o desejado.
Gostei + 0
02/10/2013
Lucas Garcia
begin
A:=false;
Ch := edtRecebeCaminho.Text;
Ch2 := edtDestino.Text;
sc_vt := FindFirst(Ch + '???????????????????.???', faArchive, sc_vai);
While sc_vt = 0 Do
Begin
If Length(sc_vai.Name) < 20 Then
Begin
sc_vt := FindNext(sc_vai);
Continue;
End;
AssignFile(arq, edtRecebeCaminho.Text + sc_vai.Name);
Reset(arq); // [ 3 ] Abre o arquivo texto para leitura
while not eof(arq) do
begin
readln(arq, linha); // [ 6 ] Lê uma linha do arquivo
T:= copy(linha, 1, 23);
if ( T = ('ALERTA : Cupom Fiscal j')) then
begin
T:= copy(linha, 27, 30);
if( T = ('registrado no sistema na linha')) then
begin
A:=true;
end;
end;
end;
CloseFile(arq);
if A=true then
begin
Ch:=Ch + sc_vai.Name;
Ch2:=Ch2 + sc_vai.Name;
MoveFile(PCHAR(Ch),PCHAR(ch2));
showmessage('Arquivos Separados');
end;
sc_vt:= FindNext(sc_vai);
end;
end;
Gostei + 0
02/10/2013
Marcos Saffran
ficou muito bom parabéns!
Sempre que possível estamos aqui para poder ajudar.
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)