Tip

Copy, Move, Delete, Rename -- Explorer Like


Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAborted As Long
hNameMaps As Long
sProgress As String
End Type

Const INVALID_HANDLE_VALUE = -1
Const MAX_PATH = 260

Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

Type WIN32_FIND_DATA
dwFileAttributes As Long ' Dateiattribute
ftCreationTime As FILETIME ' Erstellungsdatum
ftLastAccessTime As FILETIME ' Letzter Zugriff
ftLastWriteTime As FILETIME ' Letzte Speicherung
nFileSizeHigh As Long ' Gr??e (Hi)
nFileSizeLow As Long ' Gr??e (Lo)
dwReserved0 As Long ' bedeutungslos
dwReserved1 As Long ' bedeutungslos
cFileName As String * MAX_PATH ' Dateiname
cAlternate As String * 14 ' 8.3-Dateiname
End Type

Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type

Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (Byval
lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (Byval
hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Declare Function FindClose Lib "kernel32" (Byval hFindFile As Long) As Long
Declare Function SHFileOperation Lib "shell32.dll" (lpFileOp As SHFILEOPSTRUCT)
As Long
Declare Function SHEmptyRecycleBin Lib "shell32" Alias "SHEmptyRecycleBinA"
(Byval hwnd As Long, Byval pszRootPath As String, Byval dwFlags As Long) As Long

' Konstanten f?r lpFileOp.wFunc - erw?nschte Aktion
Const FO_MOVE = &H1 ' Move
Const FO_COPY = &H2 ' Copy
Const FO_DELETE = &H3 ' Delete (Recycle Bin)
Const FO_RENAME = &H4 ' Rename

' Konstanten f?r lpFileOp.fFlags - diverse Optionen
Const FOF_MULTIDESTFILES = &H1 ' pTo gibt f?r jedes Element in pFrom einen
Zielpfad an
Const FOF_SILENT = &H4 ' Keine Dialoge anzeigen
Const FOF_RENAMEONCOLLISION = &H8 ' Bei Namenskollisionen automatisch
umbenennen
Const FOF_NOCONFIRMATION = &H10 ' Keine Best?tigungen durch den Benutzer -
alle Fragen werden mit "Ja" beantwortet
Const FOF_ALLOWUNDO = &H40 ' Falls m?glich werden Undo-Informationen
gesichert
Const FOF_FILESONLY = &H80 ' Bei Angabe von WildCards (*.*) sollen nur
Dateien - nicht Verzeichnisse - ber?cksichtigt werden
Const FOF_SIMPLEPROGRESS = &H100 ' Einfacher Fortschrittsbalken - keine
Dateinamen anzeigen
Const FOF_NOCONFIRMMKDIR = &H200 ' Erzeugung von Verzeichnissen nicht
best?tigen lassen
Const FOF_NOERRORUI = &H400

Class DiskFile

Declare Private Function ExistFileDirDrive(FilePathName As String) As Integer
Declare Private Function DoIt(SHFO) As Long
Declare Private Function IsSingleFile(FileName As String) As Variant
Declare Private Function IsDriveAvailable(drivNam$) As Variant

Public Function CopyFile(SourceFile As String, DestFile As String, AFlag
As Integer) As Long

Dim SHFO As SHFILEOPSTRUCT
SHFO.wFunc = FO_COPY
SHFO.pFrom = SourceFile & vbNullChar
SHFO.pTo = DestFile & vbNullChar
SHFO.fFlags = AFlag
If IsSingleFile (SourceFile) Then
CopyFile = SHFileOperation(SHFO)
Else
If ExistFileDirDrive(SourceFile) Then
CopyFile = SHFileOperation(SHFO)
Else
CopyFile = -1
End If
End If
End Function

Public Function MoveFile(SourceFile As String, DestFile As String, AFlag
As Integer) As Long

Dim SHFO As SHFILEOPSTRUCT
SHFO.wFunc = FO_MOVE
SHFO.pFrom = SourceFile & vbNullChar
SHFO.pTo = DestFile & vbNullChar
SHFO.fFlags = AFlag<WHATLE

This was first published in November 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.