PB9,对文件操作,如何更改一个文件的文件名?

my_yinger 2009-12-08 01:55:40
PB9,对文件操作,如何更改一个文件的名字?

例如
string st_name1,st_name2

st_name1 = "D:\file.001"
st_name2 = "D:\file.002"

现如何利用变量st_name1,st_name2,将文件file.001改名为file.002 ?
...全文
563 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
leio 2009-12-09
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 my_yinger 的回复:]
pb9.0真的有filemove函数 耶
另外,
API方式:
Function boolean MoveFileA(ref string lpExistingFileName,ref string lpNewFileName) LIBRARY "kernel32.dll"

不懂呀,怎么用啊?
[/Quote]

先要申明API函数,在Global External Function或Local External Function中申明。如果连在哪里申明API都不清楚,建议找本入门书看看。

然后直接调用MoveFileA

string ls_oldfile,ls_newfile
boolean lb_return
ls_oldfile = 'c:\oldfile.dat'
ls_newfile = 'c:\newfile.dat'
lb_return = MoveFileA(ls_oldfile,ls_newfile)
if lb_return = true then
messagebox('提示','改文件名成功!')
end if
my_yinger 2009-12-09
  • 打赏
  • 举报
回复
pb9.0真的有filemove函数 耶
另外,
API方式:
Function boolean MoveFileA(ref string lpExistingFileName,ref string lpNewFileName) LIBRARY "kernel32.dll"

不懂呀,怎么用啊?
leio 2009-12-08
  • 打赏
  • 举报
回复
pb9.0以上版本直接可以用pb自己的filemove函数(9.0以下不知道可有这个函数)


API方式:
Function boolean MoveFileA(ref string lpExistingFileName,ref string lpNewFileName) LIBRARY "kernel32.dll"


sun1976 2009-12-08
  • 打赏
  • 举报
回复
尝试一下filemove(st_name1 , st_name2 )
leio 2009-12-08
  • 打赏
  • 举报
回复
DOS命令当然可以,也可以用变量。

PB联机帮助查run,就有例子。

This example runs the DOS batch file MYBATCH.BAT and passes the parameter TEST to the batch file. In the batch file, you include percent substitution characters in the commands to indicate where the parameter is used:

Run("MYBATCH.BAT TEST")

In the batch file the following statement renames FILE1 to TEST:

RENAME c:\PB\FILE1 %1
my_yinger 2009-12-08
  • 打赏
  • 举报
回复
1、文件很大,copy的方法太慢,
2、API我也想了,不会,等会的人来回答 ^_^
3、运行DOS命令不可以,试过了,确定的文件名可以,变量不可以。特别举例用了变量,因为实际工作中名字是不确定的,需要用变量。
zhgwbzhd 2009-12-08
  • 打赏
  • 举报
回复
运行一个dos命令。
ren
javaxi 2009-12-08
  • 打赏
  • 举报
回复
api
sun1976 2009-12-08
  • 打赏
  • 举报
回复
if FileCopy ( st_name1 , st_name2 , false )=1 then
filedelete(st_name1 )
end if
没有直接的方法,若不用api或命令行,以上方法可以替代,但文件大的话不好

1,079

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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