Page 1 of 2 12>
Topic Options
#86936 - 2002-07-18 02:49 PM Copy Files or Folders with Progress Bar Using Shell32
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Here's another little shell COM trick. The reference is HOWTO: Use the Animated Copy Functions in Windows 95/98/Me (Q151799), but it worked fine on my Windows 2000 PC.

code:
$Source = "E:\Shellcopy.kix"
$Destination = "C:\"
$objShell = CreateObject("Shell.Application")
$objFolder = $objShell.NameSpace($Destination)
$objFolder.CopyHere($Source, "&H0")



[ 18 July 2002, 14:49: Message edited by: Chris S. ]

Top
#86937 - 2002-07-18 02:52 PM Re: Copy Files or Folders with Progress Bar Using Shell32
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Oh, yeah. Forgot to mention that to copy a folder you just replace the filename with a foldername. Simple. [Smile]
Top
#86938 - 2002-07-18 04:16 PM Re: Copy Files or Folders with Progress Bar Using Shell32
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
this would make a tidy little UDF...
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#86939 - 2002-07-18 04:22 PM Re: Copy Files or Folders with Progress Bar Using Shell32
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Yeah, I was thinking the same thing. One could even incorporate a Move or Copy option.
Top
#86940 - 2002-07-18 05:21 PM Re: Copy Files or Folders with Progress Bar Using Shell32
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
What are the parameters for $objFolder.CopyHere($Source, "&H0")

or would a move just be a copy then delete...
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#86941 - 2002-07-18 05:27 PM Re: Copy Files or Folders with Progress Bar Using Shell32
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
This is really Sweet!

This UDF would be anything but little though... [Wink]

The option combinations are endless...

[ 18 July 2002, 17:28: Message edited by: jtokach ]
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#86942 - 2002-07-18 05:32 PM Re: Copy Files or Folders with Progress Bar Using Shell32
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
found them...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/Shell/reference/objects/folder/copyhere.asp

I'm working on a little UDF now, but I'm still a little confused about "&H0"

I'm assuming it is supposed to be a hex:0 ??
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#86943 - 2002-07-18 05:54 PM Re: Copy Files or Folders with Progress Bar Using Shell32
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
something like this??

code:
FUNCTION GuiCopy($source, $Destination, optional $move, optional $delete)

if $delete del ("$destination\*.*") endif

$objShell = CreateObject("Shell.Application")
$objFolder= $objShell.NameSpace($Destination)
$objFolder.CopyHere($Source, "&H1552")
$objShell = 0

if $move del ("$source") endif

ENDFUNCTION

of course, there is no error checking here...
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#86944 - 2002-07-18 06:05 PM Re: Copy Files or Folders with Progress Bar Using Shell32
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Put an 'optional $options' in it and put the options codes into the UDf header. Some of the options are quite useful, like 16, 256, 1024.
_________________________
There are two types of vessels, submarines and targets.

Top
#86945 - 2002-07-18 06:35 PM Re: Copy Files or Folders with Progress Bar Using Shell32
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
thats what I was thinking...

The one I have in there now in 1024, 512, and 16 as default.

I just don't like the $delete / $move options, as I can see it not working correctly in all occasions
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#86946 - 2002-07-18 07:15 PM Re: Copy Files or Folders with Progress Bar Using Shell32
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Sorry, I was in a meeting so I couldn't respond sooner. Actually, for the move you would change the command ".CopyHere" to ".MoveHere."
Top
#86947 - 2002-07-18 07:24 PM Re: Copy Files or Folders with Progress Bar Using Shell32
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Here are the values for the different options to go into fFlags...

quote:

FOF_MULTIDESTFILES As Long = &H1
FOF_CONFIRMMOUSE As Long = &H2
FOF_SILENT As Long = &H4
FOF_RENAMEONCOLLISION As Long = &H8
FOF_NOCONFIRMATION As Long = &H10
FOF_WANTMAPPINGHANDLE As Long = &H20
FOF_CREATEPROGRESSDLG As Long = &H0
FOF_ALLOWUNDO As Long = &H40
FOF_FILESONLY As Long = &H80
FOF_SIMPLEPROGRESS As Long = &H100
FOF_NOCONFIRMMKDIR As Long = &H200


Top
#86948 - 2002-07-18 08:01 PM Re: Copy Files or Folders with Progress Bar Using Shell32
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
This is what I meant by the variant in combos! This udf will be HUGE! [Smile]
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#86949 - 2002-07-18 08:10 PM Re: Copy Files or Folders with Progress Bar Using Shell32
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
no, this one is doable easily...
you just need an array and then other line which counts.
_________________________
!

download KiXnet

Top
#86950 - 2002-07-18 08:17 PM Re: Copy Files or Folders with Progress Bar Using Shell32
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
It actually seems to work without converting the fFlag variable. Just using the decimal equivalent works just fine.
Top
#86951 - 2002-07-18 09:04 PM Re: Copy Files or Folders with Progress Bar Using Shell32
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Here is what I can up with UDF-wise...

code:
break on cls

; 4 Do not display a progress dialog box.
; 8 Give the file being operated on a new name in a move, copy,
; or rename operation if a file with the target name already exists.
; 16 Respond with "Yes to All" for any dialog box that is displayed.
; 64 Preserve undo information, if possible.
; 128 Perform the operation on files only if a wildcard file name (*.*) is specified.
; 256 Display a progress dialog box but do not show the file names.
; 512 Do not confirm the creation of a new directory if the operation requires one to
; be created.
;1024 Do not display a user interface if an error occurs.
;2048 Version 4.71. Do not copy the security attributes of the file.
;4096 Only operate in the local directory. Don't operate recursively into subdirectories.
;9182 Version 5.0. Do not copy connected files as a group. Only copy the specified files.

GUICopy("Copy", "E:\cd", "C:\")
? @error

function GUICopy($CMD, $Source, $Destination, OPTIONAL $Flags)
If not $Flags $Flags=0 Endif
$objShell=CreateObject("Shell.Application")
$objFolder=$objShell.NameSpace($Destination)
Select
Case $CMD="Copy" $objFolder.CopyHere($Source, $Flags)
Case $CMD="Move" $objFolder.MoveHere($Source, $Flags)
Case 1 Beep ? "GUICopy Syntax Incorrect. Use COPY or MOVE." Exit (1)
EndSelect
Exit @error
endfunction

If you guys like it, I'll submit it.

[ 19 July 2002, 02:34: Message edited by: Chris S. ]

Top
#86952 - 2002-07-18 09:06 PM Re: Copy Files or Folders with Progress Bar Using Shell32
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
While there are a bunch of combos for this, the most common use I can see is for copying/moving file to/from a users PC and you want to present a GUI indicator that the script is doing something (give the users something to look at)... if you want it silent or etc., you can just use copy/xcopy.

There are some other featues here also, but those would be few/far between.
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#86953 - 2002-07-19 12:29 AM Re: Copy Files or Folders with Progress Bar Using Shell32
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Excellent solution. I was out in right field on this one.
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#86954 - 2002-07-19 12:32 AM Re: Copy Files or Folders with Progress Bar Using Shell32
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
But you are right about one thing, this UDF will be huge ... very popular !

[ 19 July 2002, 00:33: Message edited by: Shawn ]

Top
#86955 - 2002-07-19 02:04 AM Re: Copy Files or Folders with Progress Bar Using Shell32
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Chris,

Don't you need to destroy the object somewhere in the end before quitting?

Top
Page 1 of 2 12>


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1188 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.079 seconds in which 0.029 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org