Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
large file questions
#1
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...
#2
This is not tested.

1.
Code:
Copy      Help
;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.
Code:
Copy      Help
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
#3
3.
lets say i want to split a huge file into 200meg pieces ?



thanks
pi
#4
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!!!!!! Confusedhock:

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...
#5
concerning the 2nd question of stitching these files together.
add this to the bottom to put a new line between each of the files.

Code:
Copy      Help
,,if(eof)
,,,if _i=1
,,,,break
,,,ff.Write("[]")
,,,_i-1
,,,break

add this just after the "output file" assignment place this line.
Code:
Copy      Help
_i=files.len
An old blog on QM coding and automation.

The Macro Hook


Forum Jump:


Users browsing this thread: 1 Guest(s)