Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Quick way to find number of lines in 16GB file
Message
 
 
À
09/06/2020 18:35:13
Information générale
Forum:
Windows
Catégorie:
Informatique en général
Divers
Thread ID:
01674670
Message ID:
01674827
Vues:
32
>Here's a version that works with files larger than 2GB.
>
>
count_lines_over_2gb("C:\big.csv")
>
>
>FUNCTION count_lines_over_2gb
>LPARAMETERS tcFilename
>LOCAL lnHandle, lnLines, lcData, lnSize, lnLast
>
>    * Validate parameter
>    IF TYPE("tcFilename") != "C" OR NOT FILE(tcFilename)
>        MESSAGEBOX("Usage:  lines filename.ext", 0 + 64, "Count Lines")
>        CANCEL
>    ENDIF
>
>    DECLARE INTEGER _sopen IN msvcr71.dll STRING cFilename, INTEGER nMode, INTEGER nSharing, INTEGER nPermission
>    DECLARE INTEGER _read  IN msvcr71.dll INTEGER nHandle, STRING@ outData, INTEGER outDataLength
>    DECLARE INTEGER _close IN msvcr71.dll INTEGER nHandle
>
>    * Open the file (binary, do not deny shared access)
>    lnHandle = _sopen(tcFilename, 0x8000, 0x40, 0)
>    IF lnHandle <= 0
>        MESSAGEBOX("Error opening " + tcFilename, 0 + 64, "Count Lines")
>        CANCEL
>    ENDIF
>
>    * Count the lines
>    lnSize  = 0
>    lnLast  = 0
>    lnLines = 0
>    DO WHILE .T.
>        IF INT(lnSize / 10000000) != lnLast
>            WAIT WINDOW TRANSFORM(INT(lnSize / 1024000)) + " MB" NOWAIT
>            lnLast = INT(lnSize / 10000000)
>        ENDIF
>        lcData  = SPACE(16384000)
>        lnLength = _read(lnHandle, @lcData, LEN(lcData))
>        IF lnLength = 0
>            EXIT
>        ENDIF
>        lnLines = lnLines + OCCURS(CHR(13), lcData)
>        lnSize  = lnSize  + lnLength
>    ENDDO
>    _close(lnHandle)
>
>    * Report
>    MESSAGEBOX("File contains " + LTRIM(TRANSFORM(lnLines, "999,999,999")) + " lines." + CHR(13) + "File is " + LTRIM(TRANSFORM(lnSize, "99,999,999,999,999")) + " bytes", 0 + 64, "Count Lines")
>
How long did it take for 16 GB file?
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform