打开文件
global type gf_readfile from function_object
end type
forward prototypes
global function blob gf_readfile (string as_path, string as_file)
end prototypes
global function blob gf_readfile (string as_path, string as_file);integer li_FileNum, loops, i//wxk20110214
long flen, bytes_read, new_pos
blob b, tot_b
//得到当前选择的文件的内容大小,sle_filename包含文件所在路径及文件名
flen = FileLength(as_path)
//打开文件
li_FileNum = FileOpen(as_path,StreamMode!, Read!, LockRead!)
//由于FileRead函数一次只能读出32765大小的数据,所以先计算读取次数
IF flen > 32765 THEN
IF Mod(flen, 32765) = 0 THEN
loops = flen/32765
ELSE
loops = (flen/32765) + 1
END IF
ELSE
loops = 1
END IF
new_pos = 1
//分多次读出文件中的所有数据,放在tot_b变量中
FOR i = 1 to loops
bytes_read = FileRead(li_FileNum, b)
tot_b = tot_b + b
NEXT
//关闭文件
FileClose(li_FileNum)
return tot_b
end function
写入文件
global type gf_writefile from function_object
end type
forward prototypes
global function integer gf_writefile (string as_file_name, blob ab_to_write)
end prototypes
global function integer gf_writefile (string as_file_name, blob ab_to_write);integer li_FileNum, loops, i
long flen, bytes_read//, new_pos
blob b
flen = len(ab_to_write)
li_FileNum = FileOpen(as_file_name,StreamMode!, write!,LockReadWrite!,Replace! )
if li_filenum < 0 then
// if not this.del(as_file_name) then
// return -1
// else
li_FileNum = FileOpen(as_file_name,StreamMode!, write!,LockReadWrite!,Replace! )
if li_filenum < 0 then
return -2
end if
// end if
end if
IF flen > 32765 THEN
IF Mod(flen, 32765) = 0 THEN
loops = flen/32765
ELSE
loops = (flen/32765) + 1
END IF
ELSE
loops = 1
END IF
//new_pos = 1
FOR i = 1 to loops
filewrite(li_filenum,blobmid(ab_to_write,32765 * (i - 1) + 1,32765 ))
NEXT
FileClose(li_FileNum)
return 1
end function