VB怎么用filecopy复制文件夹?
我想要复制文件夹,filecopy要怎么用啊?如filecopy"c:\programfile","d:\programfile"。运行时说找不到路径。...
我想要复制文件夹,filecopy要怎么用啊?如 filecopy "c:\program file","d:\program file"。运行时说找不到路径。
展开
展开全部
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
展开全部
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
createobject("scripting.filesystemobject").copyfolder "c:\program file","d:\program file"
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询