OptionExplicit PrivateConst FO_COPY =&H2&'Copies the files specified 'in the pFrom member to the 'location specified in the 'pTo member. PrivateConst FO_DELETE =&H3&'Deletes the files specified 'in pFrom (pTo is ignored.) PrivateConst FO_MOVE =&H1&'Moves the files specified 'in pFrom to the location 'specified in pTo. PrivateConst FO_RENAME =&H4&'Renames the files 'specified in pFrom. PrivateConst FOF_ALLOWUNDO =&H40&'Preserve Undo information. PrivateConst FOF_CONFIRMMOUSE =&H2&'Not currently implemented. PrivateConst FOF_CREATEPROGRESSDLG =&H0&'handle to the parent 'window for the 'progress dialog box. PrivateConst FOF_FILESONLY =&H80&'Perform the operation 'on files only if a 'wildcard file name '(*.*) is specified. PrivateConst 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. PrivateConst FOF_NOCONFIRMATION =&H10&'Respond with Yes to 'All for any dialog box 'that is displayed. PrivateConst FOF_NOCONFIRMMKDIR =&H200&'Does not confirm the 'creation of a new 'directory if the 'operation requires one 'to be created. PrivateConst 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. PrivateConst FOF_SILENT =&H4&'Does not display a 'progress dialog box. PrivateConst FOF_SIMPLEPROGRESS =&H100&'Displays a progress 'dialog box but does 'not show the 'file names. PrivateConst FOF_WANTMAPPINGHANDLE =&H20& 'If FOF_RENAMEONCOLLISION is specified, 'the hNameMappings member will be filled 'in if any files were renamed. ' The SHFILOPSTRUCT is not double-word aligned. If no steps are ' taken, the last 3 variables will not be passed correctly. This ' has no impact unless the progress title needs to be changed. Private Type SHFILEOPSTRUCT hwnd AsLong wFunc AsLong pFrom AsString pTo AsString fFlags AsInteger fAnyOperationsAborted AsLong hNameMappings AsLong lpszProgressTitle AsString End Type PrivateDeclareSub CopyMemory()Sub CopyMemory Lib"KERNEL32" _ Alias"RtlMoveMemory" _ (hpvDest As Any, _ hpvSource As Any, _ ByVal cbCopy AsLong) PrivateDeclareFunction SHFileOperation()Function SHFileOperation Lib"Shell32.dll" _ Alias"SHFileOperationA" _ (lpFileOp As Any) AsLong PrivateSub Form_Load()Sub Form_Load() Check1.Caption ="Copy All Files in VB Directory" Check2.Caption ="Display Custom Message" Command1.Caption ="Copy Files" End Sub PrivateSub Command1_Click()Sub Command1_Click() Dim result AsLong Dim lenFileop AsLong Dim foBuf() AsByte Dim fileop As SHFILEOPSTRUCT lenFileop = LenB(fileop) ' double word alignment increase ReDim foBuf(1To lenFileop) ' the size of the structure. With fileop .hwnd =Me.hwnd .wFunc = FO_COPY ' The files to copy separated by Nulls and terminated by two ' nulls If Check1.Value = vbChecked Then .pFrom =Environ("windir") &"*.exe" .fFlags = FOF_SIMPLEPROGRESS Or FOF_FILESONLY Else .pFrom =Environ("windir") &"Explorer.exe" _ & vbNullChar _ &Environ("windir") &"WinHelp.exe" _ & vbNullChar _ & vbNullChar EndIf .pTo ="C: estfolder"& vbNullChar & vbNullChar If Check2.Value = vbChecked Then .fFlags = FOF_SIMPLEPROGRESS Or FOF_NOCONFIRMATION Or _ FOF_NOCONFIRMMKDIR .lpszProgressTitle ="Your custom dialog string "& _ "appears here."& vbNullChar _ & vbNullChar EndIf EndWith ' Now we need to copy the structure into a byte array Call CopyMemory(foBuf(1), fileop, lenFileop) ' Next we move the last 12 bytes by 2 to byte align the data Call CopyMemory(foBuf(19), foBuf(21), 12) result = SHFileOperation(foBuf(1)) If result <>0Then' Operation failed MsgBox Err.LastDllError 'Show the error returned from 'the API. Else If fileop.fAnyOperationsAborted <>0Then MsgBox"Operation Failed" EndIf EndIf End Sub