Option Explicit Public Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long Public Type SHFILEOPSTRUCT hWnd As Long wFunc As Long pFrom As String pTo As String fFlags As Integer fAborted As Boolean hNameMaps As Long sProgress As String End Type 'Действия для wFunc Public Const FO_MOVE = &H1 Public Const FO_COPY = &H2 Public Const FO_DELETE = &H3 Public Const FO_RENAME = &H4 'Флаги для fFlags Public Const FOF_MULTIDESTFILES = &H1 'The pTo member specifies multiple destination files (one for each source file) rather than one directory where all source files are to be deposited. Public Const FOF_CONFIRMMOUSE = &H2 'Not currently implemented. Public Const FOF_ALLOWUNDO = &H40 'Preserve Undo information, if possible. If pFrom does not contain fully qualified path and filenames, this flag is ignored. Public Const FOF_SILENT = &H4 'Does not display a progress dialog box. Public Const FOF_RENAMEONCOLLISION = &H8 'Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists. Public Const FOF_NOCONFIRMATION = &H10 'Respond with Yes to All for any dialog box that is displayed. Public Const FOF_WANTMAPPINGHANDLE = &H20 'If FOF_RENAMEONCOLLISION is specified, the hNameMappings member will be filled in if any files were renamed. Public Const FOF_FILESONLY = &H80 'Perform the operation on files only if a wildcard file name (*.*) is specified. Public Const FOF_SIMPLEPROGRESS = &H100 'Displays a progress dialog box but does not show the file names. Public Const FOF_NOCONFIRMMKDIR = &H200 'Does not confirm the creation of a new directory if the operation requires one to be created. Public Const FOF_NOERRORUI = &H400 'No user interface will be displayed if an error occurs. Public Const FOF_NOCOPYSECURITYATTRIBS = &H800 'Version 4.71. MicrosoftR Windows NTR only. The security attributes of the file will not be copied. Public Function CopyFolder(ByVal strFrom As String, ByVal strTo As String) As Long Dim SHFileOp As SHFILEOPSTRUCT strFrom = strFrom & vbNullChar With SHFileOp .wFunc = FO_COPY .pFrom = strFrom 'Если захчешь, например, чтобы не было диалога, то надо написать: '.fFlags = FOF_ALLOWUNDO + FOF_SILENT 'и т.д. просто складываешь константы .fFlags = FOF_ALLOWUNDO .pTo = strTo End With CopyFolder = SHFileOperation(SHFileOp) End Function Использование: CopyFolder "d:\doc", "c:\3"
Ответить
|