请教:pb的文件复制真难搞啊

xhzlhc 2011-11-11 02:01:13
我要把 \dir1 下的文件 按条件部分地 动态地 复制到 dir2(也是动态生成)中 请问改怎么做 我用了api的copyfile函数,这个只能在同目录下操作,不行 pb自带的filecopy 一次都没用成功过 用run(xcopy)又是全部复制\dir1 下的文件和文件夹

明天要交差,哭啊,但是太困了......

求救啊.....
...全文
284 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
sherry_huang1 2013-05-15
  • 打赏
  • 举报
回复
我也遇到这个问题,是否可以请教一下。
xhzlhc 2011-11-12
  • 打赏
  • 举报
回复
搞定,不是复制的问题,是创建文件目录的路径有问题

还有filecopy 支持相对路径

谢谢大家乐
yyoinge 2011-11-11
  • 打赏
  • 举报
回复
filecopy要使用绝对路径
hyf_0023 2011-11-11
  • 打赏
  • 举报
回复
用个比较笨的方法,先fileread,再filewrite。
integer sfn //源文件号
integer dfn //目标文件号
string bytes_read //文件数据缓冲区
integer bytes_num //读数据长度

sfn = fileopen (source, StreamMode!, Read!, Shared!)
IF sfn < 0 THEN
return sfn
END IF

dfn = fileopen (dest, StreamMode!, Write!, LockWrite!, Replace!)
IF dfn < 0 THEN
fileclose(sfn)
return dfn
END IF

//逐块读写数据
bytes_num = fileread(sfn, bytes_read)
DO WHILE bytes_num > 0
bytes_num = filewrite(dfn,bytes_read)
IF bytes_num <= 0 THEN
fileclose(sfn)
fileclose(dfn)
return bytes_num
END IF
bytes_num = fileread(sfn, bytes_read)
LOOP

fileclose(sfn)
fileclose(dfn)
return 0
xuam 2011-11-11
  • 打赏
  • 举报
回复
xcopy 可以搞定吧
xhzlhc 2011-11-11
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 yyoinge 的回复:]
跟路径名称没有关系,目标路径所在目录必须存在,也就是说目录“dir:\......\010000”必须存在
[/Quote]

dir:\......\010000 010000,010001,010002是文件名 我刚加了.txt后缀依然是遇010000就报-2错误

for k = 1 to lb_1.totalitems()
ls_tmp = lb_1.text(k)
ls_tmp_3 = ls_src + "\" + ls_tmp
ls_tmp_5 = ls_des + "\" + ls_tmp + ".txt"
messagebox ("",filecopy ( ls_tmp_3,ls_tmp_5,true) )
messagebox ("",right(ls_tmp_5,13))
next
yyoinge 2011-11-11
  • 打赏
  • 举报
回复
跟路径名称没有关系,目标路径所在目录必须存在,也就是说目录“dir:\......\010000”必须存在
xhzlhc 2011-11-11
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 yyoinge 的回复:]
filecopy 返回值是多少
[/Quote]

我跟踪了下 现在可以用了 但是存在filecopy (sr,des)= -2 这种情况是 des是 dir:\......\010000这种
结尾全是0的话 就不能复制 比如dir:\......\010001,dir:\......\010002 就能复制

这是什么原因呢
yyoinge 2011-11-11
  • 打赏
  • 举报
回复
filecopy 返回值是多少
yyoinge 2011-11-11
  • 打赏
  • 举报
回复
fileopen (dest, StreamMode!, Write!, LockWrite!, Replace!) 在文件不存在时,可以自动创建文件的
xhzlhc 2011-11-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 hyf_0023 的回复:]
用个比较笨的方法,先fileread,再filewrite。
integer sfn //源文件号
integer dfn //目标文件号
string bytes_read //文件数据缓冲区
integer bytes_num //读数据长度

sfn = fileopen (source, StreamMode!, Read!, Shared!)
IF sfn < ……
[/Quote]


大哥,谢谢你写了这么多,但是你没写创建新文件的代码
xhzlhc 2011-11-11
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 yyoinge 的回复:]
filecopy要使用绝对路径
[/Quote]
filecopy ( ls_tmp_3,ls_tmp_5,true) 我的就是绝对路径 为什么还是不行呢

740

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 脚本语言
社区管理员
  • 脚本语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧