VB怎么用filecopy复制文件夹?
发布网友
发布时间:2022-04-25 20:09
我来回答
共3个回答
热心网友
时间:2022-06-17 01:31
VB复制文件夹使用CopyFolder方法实现。
CopyFolder 方法
描述
从一个地方递归地复制一个文件夹到另一个地方。
语法
object.CopyFolder source, destination[,
overwrite]
实现代码中的source路径不能有错,否则VB报错。
将C盘下的Program Flles目录夹复制到D盘Program Flles目录夹的实际代码如下:
Private Sub Command1_Click()
CreateObject("scripting.filesystemobject").copyfolder "c:\Program Files", "D:\Program Files"
End Sub
热心网友
时间:2022-06-17 01:32
file copy 用于单个文件,用批处理更方便些。
shell"cmd.exe /c copy " & """c:\program file""" & " ""d:\program file"""""
如果非要用VB的话,我还是推荐批处理
Private Const FO_MOVE = &H1
Private Const FO_COPY = &H2
Private Const FO_DELETE = &H3
Private Const FO_RENAME = &H4
Private Const FOF_NOCONFIRMATION = &H10
Private Const FOF_SILENT = &H4
Private Const FOF_NOERRORUI = &H400
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As String 'only used if FOF_SIMPLEPROGRESS
End Type
Public Function CopyPath(ByVal mPath As String, ByVal tPath As String) As Boolean
On Error Resume Next
Dim shfileop As SHFILEOPSTRUCT
shfileop.hwnd = 0
shfileop.wFunc = FO_COPY
shfileop.pFrom = mPath
shfileop.pTo = tPath
shfileop.fFlags = FOF_NOCONFIRMATION Or FOF_SILENT Or FOF_NOERRORUI
CopyPath = Not CBool(SHFileOperation(shfileop))
End Function
热心网友
时间:2022-06-17 01:32
createobject("scripting.filesystemobject").copyfolder "c:\program file","d:\program file"