Click to See Complete Forum and Search --> : File Copy Animation(SHFileOperation)


Jeong
September 6th, 2001, 05:03 PM
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.

Braniac
September 7th, 2001, 07:51 AM
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.

Cimperiali
September 7th, 2001, 09:05 AM
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

Braniac
September 8th, 2001, 05:01 AM
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

Cimperiali
September 10th, 2001, 02:14 AM
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

Braniac
September 10th, 2001, 04:45 AM
then try to set the .fFlags = 0

Cimperiali
September 10th, 2001, 06:26 AM
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

Cimperiali
September 10th, 2001, 06:43 AM
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