Results 1 to 6 of 6

Thread: File copy

  1. #1

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471
    I need to copy a bunch of files, making the directories
    as needed. I would like to use the windows api to do this.

    Does anyone know a good method to do this?

    Bababooey
    Tatatoothy
    Mamamonkey

  2. #2
    Hyperactive Member PJB's Avatar
    Join Date
    Aug 2000
    Location
    dunno at the moment
    Posts
    302
    here's some code that Matthew Gates posted before that might help ya out, you'll obviously have to adapt it to your needs
    Code:
    Private Type SHFILEOPSTRUCT
       hWnd        As Long
       wFunc       As Long
       pFrom       As String
       pTo         As String
       fFlags      As Integer
       fAborted    As Boolean
       hNameMaps   As Long
       sProgress   As String
     End Type
      
    Private Const FO_MOVE = &H1
    Private Const FO_COPY = &H2
    Private Const FO_DELETE = &H3
    Private Const FO_RENAME = &H4
    
    Private Const FOF_SILENT = &H4
    Private Const FOF_RENAMEONCOLLISION = &H8
    Private Const FOF_NOCONFIRMATION = &H10
    Private Const FOF_SIMPLEPROGRESS = &H100
    Private Const FOF_ALLOWUNDO = &H40
    
    Private Declare Function SHFileOperation _
        Lib "shell32.dll" Alias "SHFileOperationA" _
        (lpFileOp As SHFILEOPSTRUCT) As Long
    
    Private Sub cmdBackup_Click()
    Dim SHF As SHFILEOPSTRUCT
    Dim lret As Long
    
    SHF.wFunc = FO_COPY
    SHF.hWnd = Me.hWnd
    SHF.pFrom = Dir2.Path & "*.*"
    SHF.pTo = Dir1.Path
    SHF.fFlags = FOF_NOCONFIRMATION
    
    lret = SHFileOperation(SHF)
    
    If lret <> 0 Then
        MsgBox "Error Backup aborted..."
        Dir1.Refresh
    End If
    
    If lret = 0 Then
        MsgBox "                     File Backup Successfull!                    "
        Dir1.Refresh
        Dir2.Refresh
    End If
    
    End Sub
    VB6.0 SP4
    Windows 2000
    I'm thinking of a number between

  3. #3

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471
    Thank you for your help but this will not create
    subdirectories as necessary

    Bababooey
    Tatatoothy
    Mamamonkey

  4. #4
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    It doesn't?
    strange...


    Try this one then..

    Code:
    'FileOperation
    Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
    
    'FileOperation
    Private Const FO_COPY = &H2
    Private Const FO_DELETE = &H3
    Private Const FO_MOVE = &H1
    Private Const FO_RENAME = &H4
    
    Private Const FOF_ALLOWUNDO = &H40
    Private Const FOF_CONFIRMMOUSE = &H2
    Private Const FOF_FILESONLY = &H80
    Private Const FOF_MULTIDESTFILES = &H1
    Private Const FOF_NOCONFIRMATION = &H10
    Private Const FOF_NOCONFIRMMKDIR = &H200
    Private Const FOF_RENAMEONCOLLISION = &H8
    Private Const FOF_SILENT = &H4
    Private Const FOF_SIMPLEPROGRESS = &H100
    Private Const FOF_WANTMAPPINGHANDLE = &H20
    
    'FileOperation
    Private Type SHFILEOPSTRUCT
            hwnd As Long
            wFunc As Long
            pFrom As String
            pTo As String
            fFlags As Integer
            fAnyOperationsAborted As Long
            hNameMappings As Long
            lpszProgressTitle As String '  only used if FOF_SIMPLEPROGRESS
    End Type
    
    'FileOperation
    Public Enum FileOps
            fCopy = FO_COPY
            fMove = FO_MOVE
            fDelete = FO_DELETE
            fRename = FO_RENAME
    End Enum
    
    '---//// FileOperation \\\\---
    Public Sub FileOperation(Src As String, Dest As String, Operation As FileOps, Optional Silent As Boolean = True)
    Dim tmp As SHFILEOPSTRUCT, ret&
    
        tmp.pFrom = Src
        If Len(Dest) Then tmp.pTo = Dest
        tmp.wFunc = Operation
        If Silent Then tmp.fFlags = FOF_SILENT Or FOF_NOCONFIRMATION Or FOF_NOCONFIRMMKDIR
           ret = SHFileOperation(tmp)
    End Sub
    '---//// End FileOperation \\\\---
    Hope this one works well
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  5. #5

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471
    thx for your help.
    Bababooey
    Tatatoothy
    Mamamonkey

  6. #6

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471
    woohoo WORKS!!!

    thanks again!
    Bababooey
    Tatatoothy
    Mamamonkey

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