Results 1 to 4 of 4

Thread: [RESOLVED] copy flags

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    261

    Resolved [RESOLVED] copy flags

    ive made a program to backup all my files but the problem i have is when it runs in to a problem with copying the files. i dont know what the problem is ie file corrupt or canceled by user.

    so im wantig to add some sort of way or flag for handling this.

    the code below works great for me
    i have used lngReturn = SHFileOperation(typFO) for returning cancel but cannot figure out how to get error message on file/folder/disk error

    i hope someone out there can help me???
    Code:
    Private Type SHFILEOPSTRUCT
        hWnd As Long
        wFunc As Long
        pFrom As String
        pTo As String
        fFlags As Long
        fAnyOperationsAborted As Long
        hNameMappings As Long
        lpszProgressTitle As String
    End Type
    
    Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
    Private Const FO_DELETE = &H3
    Dim Dro
    Dim DS As String
    Dim DW As String
    Dim MM
    Dim portable
    Dim DD
    Dim NewSer As String
    Dim prompt As String
    Dim DFolder As String
    Dim Dpath As String
    Dim m, d
    Dim XX As String
    Dim SHFileOp As SHFILEOPSTRUCT
    Dim lngReturn As Long
    
    Public Sub CopyFolder(ByVal Source As String, ByVal Dest As String)
        Const FO_COPY As Long = &H2
        Const FOF_NOCONFIRMATION As Long = &H10
        Const FOF_CREATEPROGRESSDLG As Long = &H0
        Const FOF_NOCONFIRMMKDIR As Long = &H200
        Const FILE_FLAGS = FOF_NOCONFIRMATION Or FOF_CREATEPROGRESSDLG Or FOF_NOCONFIRMMKDIR
        Dim typFO As SHFILEOPSTRUCT
       
        
        With typFO
            .wFunc = FO_COPY
            .fFlags = FILE_FLAGS
            .pFrom = Source 
            .pTo = Dest 
        End With
        lngReturn = SHFileOperation(typFO)
    End Sub
    Private Sub Form_Load()
    CopyFolder "c:\windowsggg", "F:\New Folder" 'this will create the problem im trying to sort out
    If lngReturn = "1026" Then
        MsgBox "problem with file"
        End If
    If lngReturn = "1223" Then
        MsgBox "canceled"
        End If
    
    End Sub
    programming pc: laptop. running xp pro and vb.net..
    media centre xp pc: dual core 6000,4gb memory, 1tb harddrive
    mainserver: server 2008, 8gb memory, amd e-350 dual core, 6tb harddrive and local web host
    atomvault 1: server 2008, atom 330 with 4 gb memory, 35TB hardrive space for videos and music..
    backup pc : xp, 4gb, atom 330, 10tb harddrive(web, pictures, music, databases)
    2 x video backup: atom 330, 2gb, 18tb harddrive
    everything on remote login..
    check out my builds http://AtomVaults.yolasite.com

    learning vb.net and php + mysql - got most of the basics now.

    I WISH THERE WAS MORE TIME IN THE DAY

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: copy flags

    Thread moved from CodeBank forum (which is for you to post your code examples, not questions)

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: copy flags


  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    261

    Re: copy flags

    thanks Joacim Andersson after looking at your link gave me a bigger picture

    this how i did if it if someone else comes across same problem
    i put in Const FOF_SILENT As Long = &H4 and added it to
    Const FILE_FLAGS = FOF_NOCONFIRMATION Or FOF_CREATEPROGRESSDLG Or FOF_NOCONFIRMMKDIR Or FOF_SILENT

    finished code(just cut and past in to a new project
    vb Code:
    1. Private Type SHFILEOPSTRUCT
    2.     hWnd As Long
    3.     wFunc As Long
    4.     pFrom As String
    5.     pTo As String
    6.     fFlags As Long
    7.     fAnyOperationsAborted As Long
    8.     hNameMappings As Long
    9.     lpszProgressTitle As String
    10. End Type
    11.  
    12. Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
    13. Private Const FO_DELETE = &H3
    14. Dim Dro
    15. Dim DS As String
    16. Dim DW As String
    17. Dim MM
    18. Dim portable
    19. Dim DD
    20. Dim NewSer As String
    21. Dim prompt As String
    22. Dim DFolder As String
    23. Dim Dpath As String
    24. Dim m, d
    25. Dim XX As String
    26. Dim lngReturn As Long
    27. Dim SHFileOp As SHFILEOPSTRUCT
    28.  
    29.  
    30. Public Sub CopyFolder(ByVal Source As String, ByVal Dest As String)
    31. 'On Error GoTo errorhanlder
    32.  
    33.     Const FO_COPY As Long = &H2
    34.     Const FOF_NOCONFIRMATION As Long = &H10
    35.     Const FOF_CREATEPROGRESSDLG As Long = &H0
    36.     Const FOF_NOCONFIRMMKDIR As Long = &H200
    37. 'new bit to keep silent and just return arror number
    38.    Const FOF_SILENT As Long = &H4
    39. '-------------------------------------------------
    40.     Const FILE_FLAGS = FOF_NOCONFIRMATION Or FOF_CREATEPROGRESSDLG Or FOF_NOCONFIRMMKDIR Or FOF_SILENT
    41.    
    42.     Dim typFO As SHFILEOPSTRUCT
    43.    
    44.    
    45.     With typFO
    46.         .wFunc = FO_COPY
    47.         .fFlags = FILE_FLAGS
    48.         .pFrom = Source
    49.         .pTo = Dest
    50.     End With
    51.     lngReturn = SHFileOperation(typFO)
    52.    
    53.     'MsgBox SHFileOperation(fAnyOperationsAborted)
    54. 'errorhanlder:
    55.    ' MsgBox Err.Number
    56. End Sub
    57.  
    58. Private Sub Form_Load()
    59. CopyFolder "c:\windowsggg", "F:\New Folder'this will creat error for the function
    60. If lngReturn = "1026" Then
    61.     MsgBox "problem with file"
    62.     End If
    63. If lngReturn = "1223" Then
    64.     MsgBox "canceled"
    65.     End If
    66.  
    67. End Sub
    Last edited by c_owl; Oct 19th, 2008 at 03:50 PM.
    programming pc: laptop. running xp pro and vb.net..
    media centre xp pc: dual core 6000,4gb memory, 1tb harddrive
    mainserver: server 2008, 8gb memory, amd e-350 dual core, 6tb harddrive and local web host
    atomvault 1: server 2008, atom 330 with 4 gb memory, 35TB hardrive space for videos and music..
    backup pc : xp, 4gb, atom 330, 10tb harddrive(web, pictures, music, databases)
    2 x video backup: atom 330, 2gb, 18tb harddrive
    everything on remote login..
    check out my builds http://AtomVaults.yolasite.com

    learning vb.net and php + mysql - got most of the basics now.

    I WISH THERE WAS MORE TIME IN THE DAY

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