Posts: 1,769
Threads: 410
Joined: Feb 2003
1.
let's say i have a large file (300+meg) and i want to see a sample of some info, say first 10 lines (or any number from anywhere). can i do that without loading the entire 300meg into a variable/memory?
2.
lets say i want to join seveal huge files (200meg a piece) do i have to load one of them into a variable/memory and do a "setfile" in order to combine them?
thanks...
Posts: 12,142
Threads: 143
Joined: Dec 2002
This is not tested.
1.
;open for reading
File f.Open("file")
;read first 10 lines
str s
int i
for i 0 10
,if(!f.ReadLine(s)) break
;read starting from 1 MB
f.SetPos(1024*1024)
f.ReadToStr(s 10)
2.
File f ff
int i eof
str buff
ARRAY(str) files.create(2) ;;input files
files[0]="file1"
files[1]="file2"
ff.Open("file3" "w") ;;output file
for i 0 files.len
,eof=0
,f.Open(files[i])
,rep
,,f.ReadToStr(buff 4096); err eof=1
,,if(buff.len) ff.Write(buff buff.len 1)
,,if(eof) break
Posts: 1,271
Threads: 399
Joined: Mar 2003
3.
lets say i want to split a huge file into 200meg pieces ?
thanks
Posts: 1,769
Threads: 410
Joined: Feb 2003
WHHHHHEEEEEEWWWWWW!!!!
Man! i hadn't realized how much better the "file peeking" method is till i was watching my system monitor. your process barely even bumped the memory or cpu but when i tred reading in and outputing the first 10 lines of an 800+ meg file on a p4 3.6 with 1 gig ram...UNSTABLE!!!!!!

hock:
i had to reboot in order to kill the qm process and my machine was terribly bogged down!
your method though was quick and unobtrusive!
thanks...
Posts: 1,769
Threads: 410
Joined: Feb 2003
concerning the 2nd question of stitching these files together.
add this to the bottom to put a new line between each of the files.
,,if(eof)
,,,if _i=1
,,,,break
,,,ff.Write("[]")
,,,_i-1
,,,break
add this just after the "output file" assignment place this line.