#86936 - 2002-07-18 02:49 PM
Copy Files or Folders with Progress Bar Using Shell32
|
Chris S.
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.
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.
|
|
Top
|
|
|
|
#86938 - 2002-07-18 04:16 PM
Re: Copy Files or Folders with Progress Bar Using Shell32
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
this would make a tidy little UDF...
|
|
Top
|
|
|
|
#86940 - 2002-07-18 05:21 PM
Re: Copy Files or Folders with Progress Bar Using Shell32
|
Radimus
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...
|
|
Top
|
|
|
|
#86943 - 2002-07-18 05:54 PM
Re: Copy Files or Folders with Progress Bar Using Shell32
|
Radimus
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...
|
|
Top
|
|
|
|
#86945 - 2002-07-18 06:35 PM
Re: Copy Files or Folders with Progress Bar Using Shell32
|
Radimus
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
|
|
Top
|
|
|
|
#86947 - 2002-07-18 07:24 PM
Re: Copy Files or Folders with Progress Bar Using Shell32
|
Chris S.
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
|
|
|
|
#86951 - 2002-07-18 09:04 PM
Re: Copy Files or Folders with Progress Bar Using Shell32
|
Chris S.
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
   
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.
|
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 1003 anonymous users online.
|
|
|