我要用VB 复制某个文件夹内的文件到另外一个文件夹内,可以实现吗?
代码越简单越好,只要能达到效果
我说的太仓促了
我有一个窗体、一个按钮控件
我点按钮就可以实现将某个文件复制到另外一个文件夹里去
例如,我要用VB实现将123.exe文件复制到另外一个文件夹里
Dim temp As Byte
Dim sfile As String, dfile As String '变量声明
Dim i As Long
sfile = "C:\123.exe"
dfile = "D:\123.exe"
Open sfile For Binary As #1 '打开源文件
Open dfile For Binary As #2 '打开目标文件
For i = 1 To LOF(1)
Get #1, i, temp '读文件
Put #2, i, temp '写文件
Next
Close '全部关闭
不是原创但能解决你的问题
Dim sfile As String, dfile As String '变量声明
Dim i As Long
sfile = "C:\123.exe"
dfile = "D:\123.exe"
Open sfile For Binary As #1 '打开源文件
Open dfile For Binary As #2 '打开目标文件
For i = 1 To LOF(1)
Get #1, i, temp '读文件
Put #2, i, temp '写文件
Next
Close '全部关闭
不是原创但能解决你的问题
温馨提示:答案为网友推荐,仅供参考
第1个回答 推荐于2016-05-26
简单的:
Private Sub Command1_Click()
filecopy "123.exe", "c:\123.exe"
End Sub追问
Private Sub Command1_Click()
filecopy "123.exe", "c:\123.exe"
End Sub追问
这个方法可以是可以,但如果另外一个文件夹中已经有这个文件了就会出错,怎么写不出错啊?
如:被复制的文件不存在,就提示文件不存在,复制到另外的文件夹中的文件已经存在那个文件夹里了,就提示文件已经存在,不能复制等等的提示
提示文件不存在就不必了,看看这样
Private Sub Command1_Click()
if dir("c:\123.exe") "" then
if msgbox("文件已存在,是否更新?", vbyesno) = vbno then
exit sub
else
kill "c:\123.exe"
filecopy "123.exe", "c:\123.exe"
end if
end if
End Sub