Results 1 to 9 of 9

Thread: Allright Guru's Here's your chance!

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2001
    Posts
    29
    I'm Having trouble with my code!
    I am trying to use SHFileOperation API to copy and rename files.
    I also could use some code to run batch files but that comes later.
    The problem with the SHFileOperation is that, it copies but doesn't rename!
    I appreciate all responses...
    Here is the code:
    --------------------------


    Option Explicit

    Private Type SHFILEOPSTRUCT
    hwnd As Long
    wFunc As Long
    pFrom As String
    pTo As String
    fFlags As Integer
    End Type

    Private Type SHFILEOPSTRUCT2
    hwnd2 As Long
    wFunc2 As Long
    pFrom2 As String
    pTo2 As String
    fFlags2 As Integer
    End Type

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

    Private Declare Function SHFileOperation2 Lib "shell32.dll" Alias "SHFileOperationA" _
    (lpFileOp2 As SHFILEOPSTRUCT2) As Long

    ' // Shell File Operations

    Const FO_MOVE = &H1
    Const FO_COPY = &H2
    Const FO_DELETE = &H3
    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:\"
    lResult = SHFileOperation(SHF) 'first copy
    If lResult Then
    MsgBox "Error in Copying files", vbInformation, "Error 1"
    End If
    Dim lResult2 As Long, SHF2 As SHFILEOPSTRUCT2
    SHF.wFunc = FO_RENAME
    SHF.pFrom = "c:\*.bat"
    SHF.pTo = "c:\*.txt"
    SHF.fFlags = FOF_SILENT
    lResult2 = SHFileOperation2(SHF2) 'then rename
    If lResult2 Then
    MsgBox "Error in renaming files", vbInformation, "Error 2"
    End If
    End Sub

    Private Sub Form_Load()
    Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2
    End Sub
    ---------------
    It works If I change these lines:
    -----
    SHF.pFrom = "c:\*.bat"
    SHF.pTo = "c:\*.txt"
    -----
    To:
    -----
    SHF.pFrom = "c:\test.bat"
    SHF.pTo = "c:\test.txt"
    -----
    WHY???????
    I NEED TO RENAME MULTIPLE FILES!!!!
    Also how do you end a command box so I don't have to x it out to end the program?

    Thanks,
    Stan
    Last edited by [email protected]; Jan 30th, 2001 at 02:33 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width