Funciones de Ficheros

Post Reply
Mike Serra
Posts: 287
Joined: Fri Apr 14, 2006 5:52 pm
Location: Córdoba (España)

Funciones de Ficheros

Post by Mike Serra »

Buenas tardes Foro, tengo una duda, tengo este código:

Code: Select all

#include "fivewin.ch"

function main()
   local nhandel,nume_line:=0,leido:="",i
   nhandel:=fopen("fcli.txt")
   nume_line = flinecount(nhandel)
   msginfo(nume_line,"Nº de lineas")
   for i = 1 to nume_line
       freadline(nHandel,@leido)
       msginfo(leido)
   next i
return

function freadline( nHandle, nLineLen )
  local cBuffer, nBytes, nAt
  DEFAULT nLineLen := 512

  cBuffer := Space( nLineLen )
  nBytes = FRead( nHandle, @cBuffer, nLineLen )
  nAt = At( Chr( 13 ) + Chr( 10 ), cBuffer )
  if nAt != 0
     FSeek( nHandle, -( nBytes - nAt + 2 ), FS_RELATIVE )
  endif
return If(nAt !=0, SubStr( cBuffer, 1, nAt - 1 ), SubStr( cBuffer, 1, Bytes))
El mensaje de los numeros de lineas me sale a 0 (funcion flinecount) y tiene muchas lineas, os lo aseguro, ¿existe otra funcion para leer el nº de lineas de un fichero que no sea flinecount, o donde puede ver su uso?

P.D. la funcion freadline la he copiado de este foro, ¿Sabeis la constante FS_RELATIVE en que fichero de encabezados está?
User avatar
jose_murugosa
Posts: 943
Joined: Mon Feb 06, 2006 4:28 pm
Location: Uruguay
Contact:

Re: Funciones de Ficheros

Post by jose_murugosa »

Mike Serra wrote:Buenas tardes Foro, tengo una duda, tengo este código:

Code: Select all

#include "fivewin.ch"

function main()
   local nhandel,nume_line:=0,leido:="",i
   nhandel:=fopen("fcli.txt")
   nume_line = flinecount(nhandel)
   msginfo(nume_line,"Nº de lineas")
   for i = 1 to nume_line
       freadline(nHandel,@leido)
       msginfo(leido)
   next i
return

function freadline( nHandle, nLineLen )
  local cBuffer, nBytes, nAt
  DEFAULT nLineLen := 512

  cBuffer := Space( nLineLen )
  nBytes = FRead( nHandle, @cBuffer, nLineLen )
  nAt = At( Chr( 13 ) + Chr( 10 ), cBuffer )
  if nAt != 0
     FSeek( nHandle, -( nBytes - nAt + 2 ), FS_RELATIVE )
  endif
return If(nAt !=0, SubStr( cBuffer, 1, nAt - 1 ), SubStr( cBuffer, 1, Bytes))
El mensaje de los numeros de lineas me sale a 0 (funcion flinecount) y tiene muchas lineas, os lo aseguro, ¿existe otra funcion para leer el nº de lineas de un fichero que no sea flinecount, o donde puede ver su uso?

P.D. la funcion freadline la he copiado de este foro, ¿Sabeis la constante FS_RELATIVE en que fichero de encabezados está?

Información de fLineCount()

FLineCount()
Counts the lines in an ASCII text file.
Syntax
FLineCount( <cFileName> ) --> nLineCount

Arguments
<cFileName>
This is a character string holding the name of the text file whose lines to count. It must include path and file extension. If the path is omitted from <cFileName>, the file is searched in the current directory. Return
The function returns the number of lines contained in <cFileName> as a numeric value. If the file <cFileName> does not exist or cannot be opened, the return value is zero.
Description
FLineCount() is an optimized function for counting the lines in an ASCII text file fast and efficiently. It can be used in conjunction with HB_FReadLine() to extract single lines from an ASCII text file.


Otra función parecida:

HB_FLastRec()
Returns the number of lines in the currently selected text file.
Syntax
HB_FLastRec() --> nLineCount

Return
The function returns the number of lines in the currently selected text file as a numeric value.
Saludos/Regards,
José Murugosa
FWH + Harbour + Bcc7. Una seda!
gabo
Posts: 117
Joined: Tue Jan 03, 2006 8:31 pm

Post by gabo »

Es mejor que uses la clase TTxtFile
Saludos
GABO
Mike Serra
Posts: 287
Joined: Fri Apr 14, 2006 5:52 pm
Location: Córdoba (España)

Post by Mike Serra »

Gracias a Jose y Gabo, Probé con la clase y me solucionó el problema. :)
Post Reply