I/O error 104

31/07/2008

0

Boa tarde a todos,

Estou tendo dificuldades p resolver esse problema de I/O error 104 na rotina abaixo:


begin
   {CARREGA ARQUIVO DE ORIGEM}

     NomeEntrada := ParamStr(1);       // Atribui a variavel NomeEntrada o nome do arquivo txt
     NomeTemp := ´C:\teste.tmp´;       // Atribui arquivo temporário

     Reset(ArqEnt,NomeEntrada);
     ReWrite(ArqSai,NomeTemp);         // Cria arquivo temporário
     ReadLn(ArqEnt,Linha);       
    
     {Verifica se não é final do arquivo de entrada}
     while not eof(ArqEnt) do
     begin
        ReadLn(ArqEnt,Linha);
       TRec.Remove([1,3],Linha);      // Chama função que ira excluir coluna 1 e 3 de arquivo txt
  
          WriteLn(ArqSai,Linha);      // Grava em Arquivo de saida  
     end;
     CloseFile(ArqEnt);
     CloseFile(ArqSai);
     DeleteFile(NomeEntrada);          // Exclui arquivo de entrada
     RenameFile(NomeTemp,NomeEntrada); // Renomei arquivo .temp

O erro está dando depois que ele le a linha
WriteLn(ArqSai,Linha); 
e retorna para o While.



Shion86

Shion86

Responder

Posts

31/07/2008

Shion86

Desculpe, acabei apertando o botao e nem expliquei direito..

O erro está dando depois que ele le a linha WriteLn(ArqSai,Linha);
e retorna para o While. Será que tem haver com a função??

Criei ela acima do programa:


class function TRec.Remove(r : array of integer;linhaarq:string):String;
  var S,StrAux,str,novastring: string;
  var i,j,ini,fim,x,h,tamanho,w: integer;
begin
  i:=1;
  j:=0;
  h:=1;
  StrAux:=´´;

  S:= Linha;
  while Pos(´;´, S) > 0 do begin
        rem[j].ini := i;
        rem[j].fim:= Pos(´;´, S);
        rem[j].coluna:=j;
        inc(j);
        i:=Pos(´;´, S)+1;
        S[Pos(´;´, S)] := ´|´;
  end;


  for i:=0 to high(r)  do begin
    for h:= 0 to  high(rem) do begin
      if r[i] = rem[h].coluna then
        begin
          ini:= rem[h].ini;
          fim:= rem[h].fim;
        for x:=ini to fim  do
          S[x]:=´ ´;

          tamanho:= length(S);
          novastring:=´´;

          for w:=1 to  tamanho do
          begin
            if S[w]<>´ ´ then
               novastring:=novastring+S[w];
            end;
          end;
      end;
  end;
    while Pos(´|´, novastring) > 0 do begin
       novastring[Pos(´|´, novastring)] := ´;´;
    end;
       Remove:=   novastring;
 end;



Responder

01/08/2008

Aroldo Zanela

Colega,

101Disk write errorReported by CloseFile, Write, WriteIn, or Flush if the disk becomes full.



Responder

01/08/2008

Aroldo Zanela

Colega,

Oops! Peguei o fragmento errado. Segue:

104File not open for inputReported by Read, Readln, Eof, Eoln, SeekEof, or SeekEoln on a text file if the file is not open for input.


Há algum comando de leitura ou escrita após o fechamento dos handles de acesso aos arquivos.


Responder

01/08/2008

Shion86

Boa Tarde ,

Arold obrigado mais uma vez pela ajuda, eu estava com problema na função e com o auxilio de um colega do trampo, conseguimos resolver o problema e implementamos tb um array dinamico.

vou postar o código aqui p alguém que precisar, possa utilizar ou ate dar outras sugestões de como fazer ..

Exemplo de arquivo txt:


1001;BRADESCO;0122;TITULAR;
1002;ITAU;0124;TITULAR;
1003;SANTANDER;0123;TITULAR;
1004;BRADESCO;0129;TITULAR;
1005;REAL;0127;TITULAR;


terei que fazer uma aplicação em console, que exclua a coluna 1 e a 3, depois grave no mesmo arquivo de origem as informações.

ficando assim:


BRADESCO;TITULAR;
ITAU;TITULAR;
SANTANDER;TITULAR;
BRADESCO;TITULAR;
REAL;TITULAR;


O código abaixo fará isso:


program COLUNA;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Dialogs,
  Classes;

type
    TRem = record
    ini, fim , coluna: integer;
  end;

  type
    TRec = class
    public function Remove(r : array of integer;linhaarq:string):String;
    public function totalColuna(linha:string):integer;
  end;

var
   rem : Array of TRem;

   //ArqEnt      : TextFile;
   //ArqSai      : TextFile;
   ArqEnt      : TStringList;
   ArqSai      : TStringList;
   Linha       : String;
   NomeEntrada : String;
   NomeTemp    : String;
   F           : TextFile;
   iCount      : Integer;
   rec         : Trec;
   total       :integer;


function TRec.totalColuna(linha:string) :integer;
var total :integer;
begin
 total:= 0;
      while Pos(´;´, linha) > 0 do begin
         linha[Pos(´;´, linha)] := ´|´;
         total:=total+1;
    end;

 result:=total;

end;

function TRec.Remove(r : array of integer;linhaarq:string):String;
  var S,StrAux,str,novastring: string;
  var i,j,ini,fim,x,h,tamanho,w: integer;
begin
  i:=1;
  j:=0;
  h:=1;
  StrAux:=´´;
  // S := ´5003;PORTO SEGURO SAUDE;1;PORTO SEGURO SAUDE;;;TITULAR;MANOEL AREIAS NETO;´;
  S:= Linha;
  while Pos(´;´, S) > 0 do begin
        rem[j].ini := i;
        rem[j].fim:= Pos(´;´, S);
        rem[j].coluna:=j;
        inc(j);
        i:=Pos(´;´, S)+1;
        S[Pos(´;´, S)] := ´|´;
  end;


  for i:=0 to high(r)  do begin
    for h:= 0 to  high(rem) do begin
        // showmessage(inttostr(h));
      if r[i] = rem[h].coluna then
        begin
          ini:= rem[h].ini;
          fim:= rem[h].fim;
        for x:=ini to fim  do
       // StrAux:= StrAux+ S[x];
          S[x]:=´_´;

          tamanho:= length(S);
          novastring:=´´;

          for w:=1 to  tamanho do
          begin
            if S[w]<>´_´ then
               novastring:=novastring+S[w];
            end;
             Break;
          end;
      end;

  end;
    while Pos(´|´, novastring) > 0 do begin
       novastring[Pos(´|´, novastring)] := ´;´;
    end;
  Remove:=   novastring;
end;

var retorno:string;


begin

  rec:= Trec.Create;

  ArqEnt := TStringList.Create;
  ArqSai := TStringList.Create;

  {ATRIBUI VALOR AS VARIÁVEIS}
  NomeEntrada := ParamStr(1);              // Atribui a variável NomeEntrada o nome do arquivo txt
  NomeTemp := ´C:\Temp.txt´;               // Atribui a variável NomeTemp o nome do arquivo de saida


  //----------------------------------------------------------------------------
   if ParamStr(1) = ´´ then
     begin
       WriteLn(´COLUNA.EXE <Arq. txt Original>                            ´);
       WriteLn(´                                                          ´);
     end;

     if ParamStr(1) = ´?´ then
       begin
         WriteLn(´PROGRAMA DE EXCLUSAO DE COLUNAS                                     ´);
         WriteLn(´                                                                    ´);
         WriteLn(´Instruções de uso :                                                 ´);
         WriteLn(´                                                                    ´);
         WriteLn(´Parametros de execução                                              ´);
         WriteLn(´                                                                    ´);
         WriteLn(´prompt: COLUNA.EXE <Arq. txt original>                              ´);
         WriteLn(´                                                                    ´);
         WriteLn(´- <arquivo txt original> :                                          ´);
         WriteLn(´  Arquivo texto de origem, com todos registros a serem importados   ´);
         WriteLn(´                                                                    ´);
         WriteLn(´                                                                    ´);
         Exit;
       end;

   //---------------------------------------------------------------------------
    {Verifica se arquivo TXT de origem existe}
   if not FileExists(ParamStr(1)) then
     begin
       WriteLn(´Arquivo "´+ParamStr(1)+´" informado nao existe´);
       Exit;
     end;
   //---------------------------------------------------------------------------
    {Carrega arquivo de entrada}
    ArqEnt.LoadFromFile(NomeEntrada);

   //---------------------------------------------------------------------------

         WriteLn(´-----------------------------------------------------´);
         WriteLn(´                                                     ´);
         WriteLn(´   PROGRAMA EXCLUSAO COLUNAS                         ´);
         WriteLn(´   COLUNA.EXE - Versao 1.00                          ´);
         WriteLn(´                                                     ´);
         WriteLn(´-----------------------------------------------------´);
         WriteLn(´                                                     ´);
         WriteLn(´Processando................. ´+ ParamStr(1)           );
         WriteLn(´                                                     ´);

   //---------------------------------------------------------------------------
    Linha :=ArqEnt.Strings[0];

    total:= rec.totalColuna(Linha);
    SetLength(rem,total);

   //---------------------------------------------------------------------------
     {Verifica arquivo de entrada ate o final}

     for iCount := 0 to ArqEnt.Count-1 do
       begin
         Linha :=ArqEnt.Strings[iCount];         // Varre linha a linha do arquivo de entrada

         retorno:=rec.Remove([0,2],Linha);       // Define a posição das colunas a serem excluídas
         //retorno:=TRec.Remove([0,2],Linha);

         ArqSai.Add(retorno);                    // Adiciona cada linha a arquivo de saida
       end;

    ArqSai.SaveToFile(NomeTemp);                 // Salva resultado no arquivo temp

   //---------------------------------------------------------------------------
    {Exclui arquivo de entrada e Renomeia arquivo de temp}

    DeleteFile(NomeEntrada);
    RenameFile(NomeTemp, NomeEntrada);

   //---------------------------------------------------------------------------

         WriteLn(´                                                     ´);
         WriteLn(´Processando Finalizado...............´                );

   //---------------------------------------------------------------------------

end.



Responder

02/08/2008

Sremulador

amigo esta faltando um reset


Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar