PDA

Click to See Complete Forum and Search --> : SHFileOperation - EASY!!!!???


stan@croftmetals.com
Jan 29th, 2001, 01:47 PM
I need Help with my code:
I am trying to copy some files from a folder and rename them.
The problem is that it won't rename?
I appreciate all responses.
____________________-
Here is my code:

Option Explicit

Private Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Boolean
hNameMappings As Long
lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS
End Type

Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" _
(lpFileOp As SHFILEOPSTRUCT) As Long

' // Shell File Operations

Const FO_MOVE = &H1
Const FO_COPY = &H2
Const FO_RENAME = &H4
Const FOF_SILENT = &H4
Const FOF_FILESONLY = &H80



Private Sub Command1_Click()
Dim lResult As Long, SHF As SHFILEOPSTRUCT
SHF.hwnd = hwnd
SHF.wFunc = FO_COPY
SHF.pFrom = "c:\test\*.bat"
SHF.pTo = "c:\"
SHF.fFlags = FOF_SILENT
SHF.fFlags = FOF_FILESONLY
lResult = SHFileOperation(SHF)
If lResult Then
MsgBox "Check your drive mappings", vbInformation, "Error occurred!"
End If
End Sub
Private Sub Command1_Click()
Dim lResult As Long, SHF As SHFILEOPSTRUCT
SHF.hwnd = hwnd
SHF.wFunc = FO_RENAME
SHF.pFrom = "c:\*.bat"
SHF.pTo = "c:\*.txt"
If lResult Then
MsgBox "Check your drive mappings", vbInformation, "Error occurred!"
End If
End Sub
Private Sub Form_Load()
Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2
End Sub

_______________________________________