I was reading up on SHFileOperation tonight I never realy used it, before just seen it in posts so I decided to read about it pretty much you can do some cool things So to same my self repeated code I made a little mod and decided to share it with you. there not really an example just the mod code but it pretty easy to work out. I am thinking of makeing a small app to maybe backup my VB folder at midnight that what got me reseaching it. anyway hope you find it of some use.
modFileOp.bas
modFileOp.bas
Code:
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Long
Private Declare Function GetDesktopWindow Lib "user32.dll" () As Long
Private Const FO_COPY As Long = &H2
Private Const FO_DELETE As Long = &H3
Private Const FO_MOVE As Long = &H1
Private Const FO_RENAME As Long = &H4
Enum TFileFlags
FOF_ALLOWUNDO = &H40
FOF_FILESONLY = &H80
FOF_MULTIDESTFILES = &H1
FOF_NOCONFIRMATION = &H10
FOF_NOCONFIRMMKDIR = &H200
FOF_SIMPLEPROGRESS = &H100
FOF_SILENT = &H4
End Enum
Private 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
Public Function SH_Copy(src As String, dest As String, cFlags As TFileFlags) As Long
Dim shFileOp As SHFILEOPSTRUCT
'Copy files or folders
shFileOp.hWnd = GetDesktopWindow
shFileOp.wFunc = FO_COPY
shFileOp.pFrom = src
shFileOp.pTo = dest
shFileOp.fFlags = cFlags
SHCopy = SHFileOperation(shFileOp)
End Function
Public Function SH_Move(src As String, dest As String, cFlags As TFileFlags) As Long
Dim shFileOp As SHFILEOPSTRUCT
'Move files or folders
shFileOp.hWnd = GetDesktopWindow
shFileOp.wFunc = FO_MOVE
shFileOp.pFrom = src
shFileOp.pTo = dest
shFileOp.fFlags = cFlags
SHMove = SHFileOperation(shFileOp)
End Function
Public Function SH_Rename(src As String, dest As String, cFlags As TFileFlags) As Long
Dim shFileOp As SHFILEOPSTRUCT
'Rename files or folders
shFileOp.hWnd = GetDesktopWindow
shFileOp.wFunc = FO_RENAME
shFileOp.pFrom = src
shFileOp.pTo = dest
shFileOp.fFlags = cFlags
SH_Rename = SHFileOperation(shFileOp)
End Function
Public Function SH_Delete(src As String, cFlags As TFileFlags) As Long
Dim shFileOp As SHFILEOPSTRUCT
'Delete files or folders
shFileOp.hWnd = GetDesktopWindow
shFileOp.wFunc = FO_DELETE
shFileOp.pFrom = src
shFileOp.fFlags = cFlags
SH_Delete = SHFileOperation(shFileOp)
End Function