Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can't get rid of strange character in M field.
Message
 
 
À
15/03/2003 14:59:36
Donald Lowrey
Data Technology Corporation
Las Vegas, Nevada, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00766126
Message ID:
00766323
Vues:
37
Don,

If those characters are always the last charaters of the file, then following code will be much faster.
*  Purpose  Remove Ctrl+Z (26-EOF) and 141 character from the end of a text file
*  Param's  The name of the file
*   Return  .T. if operation was sucessfull
LPARAMETER pcFileName
IF NOT FILE(pcFileName)
	WAIT' ERROR: FILE '+pcFileName+' DOES NOT EXIST' WINDOW
	RETURN .F.
ENDIF
LOCAL nHandle, nFileSize, cData, cNewSize, nIOError, lRet
nHandle  = FOPEN(pcFileName,2)
IF nHandle < 0
	WAIT' ERROR: CANNOT OPRN FILE '+pcFileName WINDOW
	RETURN .F.
ENDIF
* Position file pointer on the last character
nNewSize = FSEEK(nHandle,-1,2)
* Read the last byte of it
cData = FREAD(nHandle,1)
lRet = .T.
* Check if it's 26 or 141
IF ASC(cData) = 26 OR ASC(cData) = 141
	IF FCHSIZE(nHandle, nNewSize) < 0
		WAIT 'ERROR WRITING TO FILE: '+ALLTRIM(STR(FERROR())) WINDOW
		lRet = .F.
	ENDIF
ENDIF

=FCLOSE(nHandle)

RETURN lRet
You certanly would want to replace or eleminate WAIT WINDOW in the above code. :)

>Hi Hilmar
>
>I think I have it resolved. By hand, I have gone through the text files and identified the ASCII characters, principally 26 and 141. Instead of having a FOR..ENDFOR loop with a STRTRAN in between, I just added two lines:
> lcCleanStr = CHRTRAN(lcCleanStr,CHR(26),'')
> lcCleanStr = CHRTRAN(lcCleanStr,CHR(141),'')
>
>Also, this is an operation that runs for a considerable period of time. On customer locations with really large numbers of text files, it could take hours. The table involved is never closed until the operation is complete. If a table remains open, I read somewhere that Fox only actually writes to disk at certain intervals (something like once every five minutes). I have been interrupting the program after a few hundred records. I may have interrupted the operation before an actual physical write to disk, thereby getting the memo from the previous overwrite. In a Belt and Suspenders move, I also added a FLUSH every 1000 records.
>
>This seems to work fine. Thank you for your assistance.
>
>Don Lowrey
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform