第1个回答 2006-08-05
有两种方法可以实现,第一使用API函数代码如下:
Option Explicit
'声明移动文件的API函数
Private Declare Function MoveFile Lib "kernel32" Alias "MoveFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String) As Long
Private Sub Command1_Click()
Dim str1 As String
'存放原始路径
Dim str2 As String
'要复制的路径
str1 = "c:\123\"
str2 = "c:\456\123.exe"
str1 = str1 + "123.exe"
'倘若原始文件不存在
If Dir(str1) = "" Then
MsgBox "原始文件未找到!", vbOKOnly + vbExclamation
Exit Sub
End If
'移动文件
MoveFile str1, str2
MsgBox "文件移动成功!", vbOKOnly + vbInformation
End Sub
首先你要先在c盘下面建立123和456这两个文件颊
第二种方法,使用VB自身的函数实现,代码稍有变动,具体如下:
Option Explicit
Private Sub Command1_Click()
Dim str1 As String
'存放原始路径
Dim str2 As String
'要复制的路径
str1 = "c:\123\"
str2 = "c:\456\123.exe"
str1 = str1 + "123.exe"
'倘若原始文件不存在
If Dir(str1) = "" Then
MsgBox "原始文件未找到!", vbOKOnly + vbExclamation
Exit Sub
End If
FileCopy str1, str2
'复制文件
Kill str1
'删除原始文件
MsgBox "文件移动成功!", vbOKOnly + vbInformation
End Sub
OK,以上在windows xp繁体系统和VB6.0运行通过,还有什么问题请继续提出。
第2个回答 2006-08-05
你大概是想做自我复制的小程序?
一楼的可以,二楼的太繁
如果是移动,并调用自身:
Private Sub form1_load()
if app.path <>"c:\456" then
on error resume next '错误捕获
FileCopy "c:\123\xx.exe", "c:\456\xx.exe" '复制自身
shell "c:\456\xx.exe" '调用它
end
end if
end sub