VB复制文件夹是怎么搞的?
答案:4 悬赏:10
解决时间 2021-02-12 03:36
- 提问者网友:暖心后
- 2021-02-11 15:52
VB复制文件夹是怎么搞的?
最佳答案
- 二级知识专家网友:努力只為明天
- 2021-02-11 17:03
------------------------------------
'定义win文件夹操作的函数(复制和删除,其它的(移动、改名)没用到)
'删除文件夹的函数:KillPath(path)
'复制文件夹的函数:CopyPath(mpath,tPath)
'------------------------------------
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
'删除文件夹的函数:KillPath(path)
Public Function KillPath(ByVal sPath As String) As Boolean
On Error Resume Next
Dim udtPath As SHFILEOPSTRUCT
udtPath.hwnd = 0
udtPath.wFunc = FO_DELETe
udtPath.pFrom = sPath
udtPath.pTo = ""
udtPath.fFlags = FOF_NOCONFIRMATION Or FOF_SILENT Or FOF_NOERRORUI
KillPath = Not CBool(SHFileOperation(udtPath))
End Function
'复制文件夹的函数:CopyPath(mpath,tPath)
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
'------------------------
'------------------------
'定义win文件夹操作的函数(复制和删除,其它的(移动、改名)没用到)
'删除文件夹的函数:KillPath(path)
'复制文件夹的函数:CopyPath(mpath,tPath)
'------------------------------------
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
'删除文件夹的函数:KillPath(path)
Public Function KillPath(ByVal sPath As String) As Boolean
On Error Resume Next
Dim udtPath As SHFILEOPSTRUCT
udtPath.hwnd = 0
udtPath.wFunc = FO_DELETe
udtPath.pFrom = sPath
udtPath.pTo = ""
udtPath.fFlags = FOF_NOCONFIRMATION Or FOF_SILENT Or FOF_NOERRORUI
KillPath = Not CBool(SHFileOperation(udtPath))
End Function
'复制文件夹的函数:CopyPath(mpath,tPath)
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
'------------------------
'------------------------
全部回答
- 1楼网友:茫然不知崩溃
- 2021-02-11 20:18
Set fs = CreateObject("Scripting.FileSystemObject")
fs.CopyFolder path1, path2
path1 path2指源路径和目标路径.
支持网络共享路径哦
例如 fs.CopyFolder "\\server\游戏\泡泡堂\","d:\游戏\泡泡堂\"
首先要判断路径是否存在. 不存在就建立.
用 dir()判断.
- 2楼网友:我的任性你不懂
- 2021-02-11 19:28
他们说的对,如果你不会可以利用dos啊
用VB写 个批处理在隐藏执行就行了
- 3楼网友:而你却相形见绌
- 2021-02-11 18:24
这个很简单:
比如把c:\aa目录中所有文件复制到d:\aa中,只要一行代码
shell "xcopy c:\aa d:\aa\ /e /c /y", 0
/e 复制目录和子目录,包括空的
/c 即使有错误,也继续复制
/y 禁止提示以确认改写文件
后面加0表示以隐藏方式运行
加的这些参数都是为了隐蔽性和自动性加的
目标文件夹可以不用先创建,它会自动创建
要记得目标文件夹后面要加\,请参照上面的代码
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯