[PB] PB中读写文件通用的两个函数

PB中读写文件通用的两个函数

1、文件读取 :


//函数名:f_readfile
//功能:读取文件
//参数:
//  io_file:ref blob 大对象类型,存储读出的文件内容;
//  is_filename:string 文件名
//返回值:int  1-成功 0-失败

LONG ll_len
int li_FileNum,li_count,loops,i,bytes_read
blob lblb_b,tot_b
int liResult=1

ll_len=FileLength(is_filename)
IF ll_len > 32765 THEN
 IF Mod(ll_len, 32765) = 0 THEN
  loops = ll_len/32765    
 ELSE
  loops = (ll_len/32765) + 1
 END IF
ELSE
 loops = 1
END IF  

li_FileNum =  FileOpen(is_filename,StreamMode!, read!, lockread!)
if li_filenum = -1 then
 messagebox("","无法打开文件"+ is_filename)
end if

FOR i = 1 to loops
 bytes_read=FileRead(li_FileNum, lblb_b)
 if bytes_read = -1 then
        messagebox("","读取文件"+is_filename+"失败!")
    liResult = 0
    exit
 end if
 if i=1 then
  tot_b = lblb_b
 else
  tot_b = tot_b + lblb_b
 end if 
NEXT
Fileclose(li_FileNum)

if liResult = 1 then
 ib_file=tot_b
end if

return liResult

2、文件写入 :


//函数名:f_writefile
//功能:写入文件
//参数:
//  io_file:blob  大对象类型,存储将写入的文件内容;
//  is_filename:string  文件名
//返回值:int  1-成功 0-失败


uLONG ll_len,li_count,loops
int li_FileNum
blob lblb_b
int liResult = 1

ll_len=len(ib_file)
IF ll_len > 32765 THEN
 IF Mod(ll_len, 32765) = 0 THEN
  loops = ll_len/32765    
 ELSE
  loops = (ll_len/32765) + 1
 END IF
ELSE
 loops = 1
END IF  


li_FileNum =  FileOpen(is_filename,StreamMode!, write!, shared!,Replace!)
if li_FileNum = -1 then
 messagebox("系统提示","无法打开文件"+is_filename)
 return 0
end if
FOR li_count = 1 to loops
 lblb_b = blobmid( ib_file , ( li_count - 1) * 32765 + 1 , 32765 )   
 if FileWrite(li_FileNum, lblb_b) = -1 then
  messagebox("系统提示","写文件" + is_filename+"失败")
  liResult=0
  exit
 end if//8010
NEXT
Fileclose(li_FileNum)

//if liResult=1 then
// liResult = gf_setfiletime(is_filename,idt_file_time)
//end if

return liResult

 

数组函数 Pos() CloseChannel() PrintSetFont() lowerBound() Replace() ExeclRemote() PrintSetSpacing() UpperBound() Right() GetDataDDEOrigin() PrintSetup() RightTrim() GetRemote() PrintText() Blob(大二进制对象)函数 Space() OpenChanner() PrintWindth() Blob() Trim() RespondRemote() PrintX() BlobEdit() Upper() SetRemote() PrintY() BlobMid() StartHotLink() Len() 系统与环境函数 StopHotLink() 窗口操作函数 String() Clipboard() Close() CommandParm() DDE服务器函数 CloseWithReturn() 数据类型检查与转换函数 DoScript() GetCommandDDE() Open() Asc() GetApplication() GetCommandDDEOrigin() OpenSheet() Char() GetEnvironment() GetDataDDE() OpenSheetWithParm() Dec() GetFocus() GetDataOrigin() OpenWithParm() Double() Post() RespondRemote() Integer() ProfileInt() SetDataDDE() 国际化函数 Long() ProfileString() StartServerDDE() IsAllArabic() Real() Restart() StopServerDDE() IsAllHebew() Date() Run() IsAnyArabic() DateTime() Send() 文件操作函数 IsAnyHebrew() IsNumber() SetProfileString() FileClose() IsArabic() IsTime() ShowHelp() FileDelete() IsArabicAndNumbers() Time() SignalError() FileExists() IsHebrew() Yield() FileLength() IsHebrewAndNumbers() 数值计算函数 FileOPen() Reverse() Abs() 日期、时间函数 FileRead() ToAnsi() Ceiling() Day() FileSeek() ToUnicode() Cos() DayName() FileWrite() Exp() DayNumber() GetFileOpenName() 其他函数 Fact() DaysAfter() GetFileSaveName() Beep() Int() Hour() ClassName() Log() Minute() 库管理函数 DebugBreak() logTen() Month() LibraryCreate() IntLow() Max() Now() LibraryDelete() IsValid() Min() RelativeDate() LibraryDirectory() KeyDown() Mod() RelativeTime() LibraryExport() MessageBox() Pi() Second() LibraryImport() PixelsToUnits() Rand() Today() PopulatError() Randomize() Year() 打印函数 RGB() Round() Print() SetNull() Sign() 注册(Registry)函数 PrintBitmap() SetPointer() Sin() RegistryDelete() PrintCancel() SignalError() Sqrt() RegistryGet() PrintClose() UnitsToPixels() Tan() RegistryKeys() PrintDataWindow() Truncate() RegistrySet() PrintDefineFont() RegistryValues() PrintLine() 字符串操作函数 PrintOpen() Fill() 定时函数 PrintOval() Left() CPU() PrintPage() LeftTrim() Idle() PrintRect() Lower() Timer() PrintRoundRect() Match() PrintScreen() Mid() DDE客户函数 PrintSend()
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值