CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2001
    Location
    Los Angeles, CA, United States
    Posts
    47

    File Copy Animation(SHFileOperation)

    I use the SHFileOperation function to implement file copy animation.
    But there's one problem.
    There's files to copy in different directories.
    For example, Files to copy exists in c:\test\a.txt and in c:\test1\b.txt, in this case, file copy animation disappears at the point of time that first copy is finished. And re-appears at the time that second copy starts.
    How can I solve this problem?
    Could anyone who know it let me know the way?
    Thank you

    I'm a senior programmer.
    Working at CamSight, Dental imaging solutions industry.

  2. #2
    Join Date
    Sep 2001
    Posts
    27

    Re: File Copy Animation(SHFileOperation)

    You have to combine the sourcefiles and the destinations with a Nullchar.

    Dim source as String
    Dim dest as String

    source = file1 & vbNullChar & file2 & vbNullChar & file3 & vbNullChar 'etc....
    dest = dest1 & vbNullChar & dest2 & vbNullChar & dest3 & vbNullChar 'etc....

    Then call the FileOp with
    .pFrom = source & vbNullChar & vbNullChar
    .pTo = dest & vbNullChar & vbNullChar

    it should work.

    Grzzz, Braniac.



  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: File Copy Animation(SHFileOperation)

    I tried it. The file are copied, but the progress dialog does not show
    up...What am I missing?


    'a command button
    ' a commondialog (named CDbox)
    option Explicit
    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_COPY = &H2
    'private Const cdlOFNAllowMultiselect = &H200
    private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp as SHFILEOPSTRUCT) as Long

    private Sub Command1_Click()
    'You have to combine the sourcefiles and the destinations with a Nullchar.
    Dim SHFileOp as SHFILEOPSTRUCT
    Dim lngX as Long
    Dim tmpsource, tmpdest, source, dest, ret
    on error GoTo ErrHandler
    CDbox.CancelError = true
    CDbox.DialogTitle = "Select a file to delete ..."
    'set the dialog's filter

    CDbox.Filter = "All Files (*.*)|*.*"
    'Show the 'Open File' dialog
    CDbox.Flags = cdlOFNAllowMultiselect
    CDbox.MaxFileSize = 30000
    CDbox.ShowOpen

    tmpsource = Split(CDbox.FileName, " ")
    tmpdest = tmpsource
    If UBound(tmpsource) > 0 then
    for lngX = 1 to UBound(tmpsource)
    tmpsource(lngX) = tmpsource(0) & "\" & tmpsource(lngX)
    tmpdest(lngX) = "C:\temp\moved\" & tmpsource(lngX)
    next
    'tmpsource(0) = tmpsource(0) & "\" & tmpsource(UBound(tmpsource))
    tmpsource(0) = tmpsource(UBound(tmpsource))
    tmpdest(0) = "C:\temp\moved\" '& tmpdest(UBound(tmpdest))
    ReDim Preserve tmpsource(UBound(tmpsource) - 1)
    'ReDim Preserve tmpdest(UBound(tmpdest) - 1)
    for lngX = 0 to UBound(tmpsource)
    source = source & tmpsource(lngX) & vbNullChar
    dest = dest & tmpdest(lngX) & vbNullChar
    next
    else
    source = CDbox.FileName
    ret = InStrRev(source, "\", , vbBinaryCompare)
    If ret > 0 then

    dest = "C:\temp\moved\" & Right(source, len(source) - ret)

    else
    Exit Sub
    End If
    End If

    With SHFileOp
    'Copy the files
    .wFunc = FO_COPY
    'Select the file

    .pFrom = source & vbNullChar '& vbNullChar 'CDBox.FileName & vbNullChar & vbNullChar
    .pTo = dest & vbNullChar '& vbNullChar
    .sProgress = "Copying files..."
    'Allow 'move to recycle bn'

    End With
    'perform file operation
    ret = SHFileOperation(SHFileOp)
    If ret = 0 then
    MsgBox "The file '" + CDbox.FileName + "' has been copied to 'C:\temp\moved\' ", vbInformation + vbOKOnly, App.Title
    End If
    '-------------------
    exit_sub:
    Exit Sub
    ErrHandler:
    If CDbox.FileName = "" then
    resume exit_sub
    else
    resume next
    End If

    End Sub





    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  4. #4
    Join Date
    Sep 2001
    Posts
    27

    Re: File Copy Animation(SHFileOperation)

    With SHFileOp 'Copy the files
    .wFunc = FO_COPY 'Select the file
    .pFrom = source & vbNullChar '& vbNullChar 'CDBox.FileName &
    .pTo = dest & vbNullChar '& vbNullChar
    .sProgress = "Copying files..."
    'Allow 'move to recycle bn'

    'you forgot this one:
    .fFlags = FOF_NOCONFIRMATION

    End With


  5. #5
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: File Copy Animation(SHFileOperation)

    I added it. Files are copied, but no animation is showed... Thanks anyway.
    Cesare

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  6. #6
    Join Date
    Sep 2001
    Posts
    27

    Re: File Copy Animation(SHFileOperation)

    then try to set the .fFlags = 0


  7. #7
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    noAnimation(SHFileOperation)

    The same: files are copied, but no animation is shown. Thanks anyway.

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  8. #8
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: File Copy Animation(SHFileOperation)

    Better seems:
    .fFlags = FOF_NOCONFIRMATION And FOF_SIMPLEPROGRESS
    However, I founded out:matter is, if files are light, I see no animation as
    the operation ended before...If I add to copy array large files (over 10 mb), I will see the animation.
    Thanks, and sorry for me not found it before.

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

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

Featured