Click to See Complete Forum and Search --> : SHFileOperation Option In Case Of Copying Folder


Jeong
September 12th, 2001, 04:04 PM
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.

Cimperiali
September 13th, 2001, 04:22 AM
'"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