Added: Aug 19, 2002
Snippet uploaded by: snippet
Written By: Unknown
Demo: Sorry, no demo
FileMove / Del Animation / API Calls
Highlight all by clicking in box
Public Type SHFILEOPSTRUCT
hWnd As Long 'an hWnd of a form
wFunc As Long 'one of the File Operation Consts
pFrom As String 'Source path and file
pTo As String 'Destination path and file
fFlags As Long 'Combination of the FOF_ flags
fAnyOperationsAborted As Long 'Flag indicating that operations did not
hNameMappings As Long 'Pointer to name maps for files that were
renamed To avoid conflicts
lpszProgressTitle As String 'Caption to appear in title bar of
'File Operation constants
Public Enum FO_OPS
FO_MOVE = &H1
FO_COPY = &H2
FO_DELETE = &H3
FO_RENAME = &H4
'File Operation Flag Constants
Public Enum FO_FLAGS
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.
FOF_CONFIRMMOUSE = &H2 'Not currently implemented.
FOF_SILENT = &H4 'Does not display a progress dialog box.
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
FOF_NOCONFIRMATION = &H10 'Respond with Yes to All for any dialog box
that Is displayed.
FOF_WANTMAPPINGHANDLE = &H20 'If FOF_RENAMEONCOLLISION is specified,
the hNameMappings member will be filled In If any files were renamed.
FOF_CREATEPROGRESSDLG = &H0 '
FOF_ALLOWUNDO = &H40 'Preserve Undo information, if possible.
FOF_FILESONLY = &H80 'Perform the operation on files only if a wildcard
file Name (*.*) Is specified.
FOF_SIMPLEPROGRESS = &H100 'Displays a progress dialog box but does not
show the file names.
FOF_NOCONFIRMMKDIR = &H200 'Does not confirm the creation of a new
directory If the operation requires one To be created.
FOF_NOERRORUI = &H400 'No user interface will be displayed if an error
Public Declare Function SHFileOperation Lib "shell32.dll" Alias
(lpFileOp As SHFILEOPSTRUCT) As Long
Public Sub Copy(Source As String, Destination As String, _
Optional Options As FO_FLAGS = FOF_CREATEPROGRESSDLG Or
'Remarks: - Copies files from a supplied source to a supplied
' and creates any needed directory structure if it
does Not exist
'Author: - Craig Hunt, AISA Logic, Inc.
'Input: - Source - a null character delimited, 2 null
' string of source files to copy.
' (eg "c:my documentsfile.xls & chr(0) & c:my
' & chr(0) & chr(0))
' Destination - a null character delimited, 2 null
' string of destination directories to which to copy
' Options - one or more of the FO_FLAGS enum constants
'Returns: - Nothing
Dim lRet As Long
Dim SHFileOp As SHFILEOPSTRUCT
On Error GoTo Copy_Err
'ensure source and destination strings have valid terminators
While Not Right(Source, 2) <> vbNullChar & vbNullChar
Source = Source & vbNullChar
While Not Right(Destination, 2) <> vbNullChar & vbNullChar
Destination = Destination & vbNullChar
.wFunc = FO_COPY
.pFrom = Source
.pTo = Destination
.fFlags = Options
lRet = SHFileOperation(SHFileOp)
MsgBox Error, vbCritical
'You could modify this code To accommodate move And 'delete by using the
'FO_OPS Enum For the wFunc Property If the SHFileOp 'structure.;
No Comments to show
Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.
Adding your comment. Please wait...
Thanks for adding your comment!. After further review it will be added.
There was a problem adding your comment. Please try again.
Please complete all the fields in the form before sending.