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

    SHFileOperation Option In Case Of Copying Folder

    I implemented file copy animation using SHFileOperation function.
    In case of file copy, it works well.
    But in case of folder copy, it doesn't work.
    How can I implement it?
    It seems that fFlags of the SHFILEOPSTRUCT is invalid.
    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
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: SHFileOperation Option In Case Of Copying Folder


    '"c:\temp\copyed" must exist on your pc
    ' this will copy it inside the dir "C:\temp\moved" (created if non exist)
    'You will see the animation only if the source dir is heavy.
    'If it is light (ie: under 5-10 MB) you will not see any animation
    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 FO_DELETE = &H3
    private Const FOF_ALLOWUNDO = &H40
    private Const FOF_NOCONFIRMATION = &H10
    private Const FOF_SIMPLEPROGRESS = &H100
    '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 source, dest, ret
    'on error GoTo ErrHandler
    source = "c:\temp\copyed"
    dest = "C:\temp\moved"
    If Dir("C:\temp\moved", vbDirectory) = "" then
    MkDir "C:\temp\moved"
    End If
    ''on error resume next
    ' 'Kill "C:\temp\moved\*.*"
    '' If Err > 0 then
    ' ' Err.Clear
    '' End If
    ''on error GoTo 0
    With SHFileOp
    'Delete the file
    .wFunc = FO_COPY
    'Select the file

    .pFrom = source & vbNullChar & vbNullChar
    .pTo = dest & vbNullChar & vbNullChar
    .sProgress = "Copying Dir..."
    'Allow 'move to recycle bn'
    .fFlags = FOF_NOCONFIRMATION And FOF_SIMPLEPROGRESS
    '.fFlags = 0
    End With
    'perform file operation
    ret = SHFileOperation(SHFileOp)
    If ret = 0 then
    MsgBox "Dir copied to ''c:\temp\moved''"
    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.

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