vb怎么转移指定文件到某个指定处?回答加50

2025-03-30 00:50:33
推荐回答(3个)
回答1:

抛砖引玉:
Sub manip_file()
'请先引用 Microsoft ScriptingRuntime
Dim fso As New FileSystemObject, txtfile, fil1, fil2
Set txtfile = fso.CreateTextFile("c:\test.txt", True)
MsgBox "写入文件"
'写入一行
txtfile.Write ("This is a test")
'关闭写入的文件
txtfile.Close
MsgBox "创建文件夹c:\temp,移动文件到c:\temp", , "移动文件"
'获得根目录下的一个文件句柄
Set fil1 = fso.GetFile("c:\test.txt")
fso.CreateFolder ("c:\temp")
fil1.Move ("c:\temp\test.txt")
MsgBox "创建文件夹c:\tmp,且复制文件到c:\tmp", , "复制文件"
fso.CreateFolder ("c:\tmp")
fil1.Copy ("c:\tmp\test.txt")
MsgBox "删除文件"
Set fil1 = fso.GetFile("c:\temp\test.txt")
Set fil2 = fso.GetFile("c:\tmp\test.txt")
fil1.Delete
fil2.Delete
fso.DeleteFolder ("c:\tmp")
fso.DeleteFolder ("c:\temp")
MsgBox "It's OK"
End Sub

Private Sub Command2_Click()
Call manip_file
End Sub

回答2:

Private Sub Command1_Click()
If Dir("D:\file\1\123.txt") <> "" Then '先判断有没有该文件存在
FileCopy "D:\file\1\123.txt", "D:\file\2\123.txt" '从1文件夹里复制到2文件夹里
Kill "D:\file\1\123.txt" '再把1文件夹里的删除了实现剪切的效果
Else
MsgBox "没有找到该文件"
End If
End Sub

楼下的,name无法跨驱动器移动的。

回答3:

name "原路径" as "新路径"