Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
8
Erster Beitrag:
vor 3 Monaten, 4 Wochen
Letzter Beitrag:
vor 3 Monaten, 3 Wochen
Beteiligte Autoren:
Randall, GuenterP, Fabrice Harari

[WB19,20,21] fseek for external file

Startbeitrag von Randall am 26.04.2017 16:17

I need to traverse an external file, back and forth from beginning to end several times because the strings aren't in any order. I tried using fseek to return to the beginning of the file by passing it 0, fpbeginning and also -16981, fpcurrent (which is fsize of the file). But neither of these work. Will I have to close and reopen the file several times in order to get back to the beginning?

Thanks in advance for any help on this...

Antworten:

Hi,

if the file is smaller than 4 Gb the you can / should load it into a string and deal with the contents of the string using string-functions.

von GuenterP - am 26.04.2017 16:56
Thank you Guenter, would I use floadbuffer? If so, how do I find the bytes to end of file for the size parameter? Or, floadtext? Then, how would I traverse down through each row? (in order to pick up the contents of each string with extractstring.)

von Randall - am 28.04.2017 12:00
Hi fLoadText(..) would be appropriate. You can retrieve the string size by NoSpace(YourString) then and retrieve parts of the file by Position or best by ExtractString. Or you could load an array with it and use arraysearch ...

von GuenterP - am 28.04.2017 12:51
Thank you for your reply Guenter. I tried using the fLoadText and it loaded slightly more than half of a 17kb file... about 16 and a half of the 25 lines. ExtractString works great to pick up a line of the file but I'm still unable to iterate through the file contents... and that won't be possible if I can't bring the whole file into fLoadText. It seems to me that it would be easiest if I could get positioned back at the beginning of the file after traversing through it using fReadLine.

I'm basically trying to look through a second file, using a key identifier, to see if it has additional information associated with a data string I'm looking at in the first file. It works great the first time through, then it sits at EOT.

von Randall - am 01.05.2017 18:56
Hi Randall,

I believe, there's something really wrong with your text file. I never ever experienced a partial loading of a text file! Did you set foAnsi / foUnicode according to the character set used in that file?

von GuenterP - am 02.05.2017 04:42
Hi Randall,

a follow up to Guenter's answer

It looks to me like you have at least one binary ZERO in your "text" file

So either it contains a mix of ansi/unicode or it is plain broken
A simple view with an Hex editor will tell you

Best regards

von Fabrice Harari - am 02.05.2017 10:51
I'm receiving the text file from a 3rd party. If there's an error in one or more of the file strings, it's information I'm not needing. Anyway, this appears to take me back to beginning of the file. Yay! Thank you both for your replies...

xBot is numeric = fSeek(txtDetailId,0,fpCurrent)
xBot -= (2 * xBot)
fSeek(txtDetailId,xBot,fpCurrent)
txtDetailLn = fReadLine(txtDetailId)

von Randall - am 02.05.2017 19:18
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.