Set fso = New FileSystemObject fso.CopyFolder "a:\", "d:\bp" & Frame3.Caption, True 为什么报错?"无效的过程调用或参数"
"d:\bp" & Frame3.Caption 有问题吧?
Dim fso As FileSystemObject dim strDir As String strDir = "d:\bp\" & Frame3.Caption fso.CopyFolder "A:", strDir, True这样也不行呀?请看看.
用API,我有源代码呀,要吗。
如何用程序来Delete Copy Move Rename File/Directory
作者: 王国荣 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 'wFunc 的设定值 'FO_COPY Copies the files specified by pFrom to the location specified by pTo. 'FO_DELETE Deletes the files specified by pFrom (pTo is ignored). 'FO_MOVE Moves the files specified by pFrom to the location specified by pTo. 'FO_RENAME Renames the files specified by pFrom.'fFlag的设定 'FOF_ALLOWUNDO Preserves undo information, if possible. 'FOF_FILESONLY Performs the operation only on files if a wildcard filename ' (*.*) is specified. 'FOF_MULTIDESTFILES Indicates that the pTo member specifies multiple destination ' files (one for each source file) rather than one directory where ' all source files are to be deposited. 'FOF_NOCONFIRMATION Responds with "yes to all" for any dialog box that is displayed. 'FOF_NOCONFIRMMKDIR Does not confirm the creation of a new directory if ' the operation requires one to be created. 'FOF_RENAMEONCOLLISION Gives the file being operated on a new name (such as ' "Copy #1 of...") in a move, copy, or rename operation ' if a file of the target name already exists. 'FOF_SILENT Does not display a progress dialog box. 'FOF_SIMPLEPROGRESS Displays a progress dialog box, but does not show the ' filenames. 'FOF_WANTMAPPINGHANDLE Fills in the hNameMappings member. The handle must be ' freed by using the SHFreeNameMappings function.Const FO_MOVE = &H1 Const FO_COPY = &H2 Const FO_DELETE = &H3 Const FOF_NOCONFIRMATION = &H10 Const FOF_NOCONFIRMMKDIR = &H200 Const FOF_ALLOWUNDO = &H40 Const FOF_SILENT = &H4 Private Declare Function SHFileOperation Lib "shell32.dll" Alias _ "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long'删除 test目录及其底下的子目录到资源回收桶 Private Sub Command1_Click() Dim SHFileOp As SHFILEOPSTRUCT SHFileOp.wFunc = FO_DELETE SHFileOp.pFrom = "c:\test" + Chr(0) '不出现档案删除的动态AVI,且不Confirm SHFileOp.fFlags = FOF_SILENT + FOF_ALLOWUNDO + FOF_NOCONFIRMATION '若没有 FOF_ALLOWUNDO 则不会到资源回收桶 Call SHFileOperation(SHFileOp) End Sub'同时删除多档到资源回收桶 Private Sub Command2_Click() Dim SHFileOp As SHFILEOPSTRUCT Dim Files As String 'Files = "c:\test.txt" + Chr(0) Files = "c:\test1.txt" + Chr(0) + "c:\test2.txt" + Chr(0) + _ "c:\test3.txt" + Chr(0) SHFileOp.wFunc = FO_DELETE SHFileOp.pFrom = Files '删至资源回收桶,且不Confirm SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMATION Call SHFileOperation(SHFileOp) End Sub'将 c:\temp 整个目录复制到 c:\temp2 Private Sub Command3_Click() Dim SHFileOp As SHFILEOPSTRUCT SHFileOp.wFunc = FO_COPY SHFileOp.pFrom = "c:\temp\*.*" SHFileOp.pTo = "c:\temp2\*.*" SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMMKDIR Call SHFileOperation(SHFileOp) End Sub'将 c:\test4.txt 快速移到 c:\temp 目录 Private Sub Command4_Click() Dim SHFileOp As SHFILEOPSTRUCT SHFileOp.wFunc = FO_MOVE SHFileOp.pFrom = "c:\test4.txt" + Chr(0) SHFileOp.pTo = "c:\temp" SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMATION Call SHFileOperation(SHFileOp) End Sub
描述从一个地方递归地复制一个文件夹到另一个地方。语法object.CopyFolder source, destination[, overwrite]CopyFolder 方法语法有如下几部分:部分 描述
Object 必需的。始终为一个 FileSystemObject 的名字。
source 必需的。指明一个或多个被复制文件夹的字符串文件夹说明,可以包括通配符。
destination 必需的。指明 source 中被复制文件夹和子文件夹的接受端的字符串,不允许有通配符。
overwrite 选项的。Boolean 值,它表示已存在的文件夹是否被覆盖。如果为 True,文件被覆盖。如果为 False,文件不被覆盖。缺省值为 True。
说明通配符仅可用于 source 参数的最后一个路径部件。例如你可以在下面情况使用它:FileSystemObject.CopyFolder "c:\mydocuments\letters\*", "c:\tempfolder\"但不能在下面情况使用它:FileSystemObject.CopyFolder "c:\mydocuments\*\*", "c:\tempfolder\"如果 source 包含通配符或 destination 以路径分隔符(\)为结尾,则认为 destination 是一个已存在的文件夹,在其中复制相匹配的文件夹和子文件夹。否则认为 destination 是一个要创建的文件夹的名字。不论何种情况,当复制一个文件夹时,可能发生四种事件。 如果 destination 不存在,source 文件夹和它所有的内容得到复制。这是通常的情况。
如果 destination 是一个已存在的文件,则发生一个错误。
如果 destination 是一个目录,它将尝试复制文件夹和它所有的内容。如果一个包含在 source 的文件已在 destination 中存在,当 overwrite 为 False 时发生一个错误,否则它将尝试覆盖这个文件。
如果 destination 是一个只读目录,当尝试去复制一个已存在的只读文件到此目录并且 overwrite为 False 时,则发生一个错误。
如果 source 使用的通配符不能和任何文件夹匹配,也发生一个错误。CopyFolder 方法停止在它遇到的第一个错误上。不要尝试回卷错误发生前所做的任何改变。
引用microsoft scripting runtimeDim fso As FileSystemObject
fso.CopyFolder "目录a", "目录b", true '如果目录b存在,覆盖。
fso.CopyFolder "a:\", "d:\bp" & Frame3.Caption, True
为什么报错?"无效的过程调用或参数"
有问题吧?
dim strDir As String
strDir = "d:\bp\" & Frame3.Caption
fso.CopyFolder "A:", strDir, True这样也不行呀?请看看.
如何用程序来Delete Copy Move Rename File/Directory
作者: 王国荣 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
'wFunc 的设定值
'FO_COPY Copies the files specified by pFrom to the location specified by pTo.
'FO_DELETE Deletes the files specified by pFrom (pTo is ignored).
'FO_MOVE Moves the files specified by pFrom to the location specified by pTo.
'FO_RENAME Renames the files specified by pFrom.'fFlag的设定
'FOF_ALLOWUNDO Preserves undo information, if possible.
'FOF_FILESONLY Performs the operation only on files if a wildcard filename
' (*.*) is specified.
'FOF_MULTIDESTFILES Indicates that the pTo member specifies multiple destination
' files (one for each source file) rather than one directory where
' all source files are to be deposited.
'FOF_NOCONFIRMATION Responds with "yes to all" for any dialog box that is displayed.
'FOF_NOCONFIRMMKDIR Does not confirm the creation of a new directory if
' the operation requires one to be created.
'FOF_RENAMEONCOLLISION Gives the file being operated on a new name (such as
' "Copy #1 of...") in a move, copy, or rename operation
' if a file of the target name already exists.
'FOF_SILENT Does not display a progress dialog box.
'FOF_SIMPLEPROGRESS Displays a progress dialog box, but does not show the
' filenames.
'FOF_WANTMAPPINGHANDLE Fills in the hNameMappings member. The handle must be
' freed by using the SHFreeNameMappings function.Const FO_MOVE = &H1
Const FO_COPY = &H2
Const FO_DELETE = &H3
Const FOF_NOCONFIRMATION = &H10
Const FOF_NOCONFIRMMKDIR = &H200
Const FOF_ALLOWUNDO = &H40
Const FOF_SILENT = &H4
Private Declare Function SHFileOperation Lib "shell32.dll" Alias _
"SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long'删除 test目录及其底下的子目录到资源回收桶
Private Sub Command1_Click()
Dim SHFileOp As SHFILEOPSTRUCT SHFileOp.wFunc = FO_DELETE
SHFileOp.pFrom = "c:\test" + Chr(0)
'不出现档案删除的动态AVI,且不Confirm
SHFileOp.fFlags = FOF_SILENT + FOF_ALLOWUNDO + FOF_NOCONFIRMATION
'若没有 FOF_ALLOWUNDO 则不会到资源回收桶
Call SHFileOperation(SHFileOp)
End Sub'同时删除多档到资源回收桶
Private Sub Command2_Click()
Dim SHFileOp As SHFILEOPSTRUCT
Dim Files As String
'Files = "c:\test.txt" + Chr(0)
Files = "c:\test1.txt" + Chr(0) + "c:\test2.txt" + Chr(0) + _
"c:\test3.txt" + Chr(0)
SHFileOp.wFunc = FO_DELETE
SHFileOp.pFrom = Files
'删至资源回收桶,且不Confirm
SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMATION
Call SHFileOperation(SHFileOp)
End Sub'将 c:\temp 整个目录复制到 c:\temp2
Private Sub Command3_Click()
Dim SHFileOp As SHFILEOPSTRUCT SHFileOp.wFunc = FO_COPY
SHFileOp.pFrom = "c:\temp\*.*"
SHFileOp.pTo = "c:\temp2\*.*"
SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMMKDIR
Call SHFileOperation(SHFileOp)
End Sub'将 c:\test4.txt 快速移到 c:\temp 目录
Private Sub Command4_Click()
Dim SHFileOp As SHFILEOPSTRUCT SHFileOp.wFunc = FO_MOVE
SHFileOp.pFrom = "c:\test4.txt" + Chr(0)
SHFileOp.pTo = "c:\temp"
SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMATION
Call SHFileOperation(SHFileOp)
End Sub