Discussion:
File Copying with Win Shell Object
(too old to reply)
scott
2007-07-13 19:15:40 UTC
Permalink
Is there any way to exclude folders and files when copying with the
Folder.CopyHere method? I want to use the CopyHere method to copy files
because of it's nice progress bar, but need the flexibility of FSO's
similiar copy command.


CODE: **********************

Const FOF_CREATEPROGRESSDLG = &H0&
sParentFolder = "D:\backup"
sFolderSource="c:\data\databases\"

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(sParentFolder)
objFolder.CopyHere sFolderSource, FOF_CREATEPROGRESSDLG
Alexander Mueller
2007-07-13 21:27:32 UTC
Permalink
Post by scott
Is there any way to exclude folders and files when copying with the
Folder.CopyHere method? I want to use the CopyHere method to copy files
because of it's nice progress bar, but need the flexibility of FSO's
similiar copy command.
CODE: **********************
Const FOF_CREATEPROGRESSDLG = &H0&
sParentFolder = "D:\backup"
sFolderSource="c:\data\databases\"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(sParentFolder)
objFolder.CopyHere sFolderSource, FOF_CREATEPROGRESSDLG
Hi

Since CopyHere also accepts a FolderItems-object as
source, you could use its Filter-method of to exclude some items.
However you must apply a filter-mask such as in the windows
filesearch (with * and ? as "jokers"), no explicit list of files to
exclude is accepted.

See sample code below.

MfG,
Alex


'CopyHere Flags YesToAll, AutoCreateDir
Const FOF_NOCONFIRMATION = &H10
Const FOF_NOCONFIRMMKDIR = &H200


srcFolder = "C:\WINDOWS\"
destFolder = "C:\_TEST" 'must exist!

'#Copy all files with an 'i' in Windir
'# to a dest folder

ShellCopyFilesFiltered srcFolder, destFolder, "*i*.*", FOF_NOCONFIRMMKDIR Or FOF_NOCONFIRMATION


Sub ShellCopyFilesFiltered(src, dest, filter, copyFlag)

Const SHCONTF_FOLDERS = 32
Const SHCONTF_NONFOLDERS = 64
Const SHCONTF_INCLUDEHIDDEN = 128

Dim sh
Dim colSrcFiles
Dim oDestFolder
Dim fltFlag
Dim cpyFlag

Set sh = CreateObject("Shell.Application")
Set oDestFolder = sh.NameSpace(dest)
Set colSrcFiles = sh.NameSpace(src).Items()

'All files, no folders
fltFlag = SHCONTF_NONFOLDERS OR SHCONTF_INCLUDEHIDDEN

colSrcFiles.Filter fltFlag, filter
oDestFolder.CopyHere colSrcFiles, copyFlag

End Sub
scott
2007-07-13 22:26:33 UTC
Permalink
thanks, i'll look into this method.
Post by Alexander Mueller
Post by scott
Is there any way to exclude folders and files when copying with the
Folder.CopyHere method? I want to use the CopyHere method to copy files
because of it's nice progress bar, but need the flexibility of FSO's
similiar copy command.
CODE: **********************
Const FOF_CREATEPROGRESSDLG = &H0&
sParentFolder = "D:\backup"
sFolderSource="c:\data\databases\"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(sParentFolder)
objFolder.CopyHere sFolderSource, FOF_CREATEPROGRESSDLG
Hi
Since CopyHere also accepts a FolderItems-object as
source, you could use its Filter-method of to exclude some items.
However you must apply a filter-mask such as in the windows
filesearch (with * and ? as "jokers"), no explicit list of files to
exclude is accepted.
See sample code below.
MfG,
Alex
'CopyHere Flags YesToAll, AutoCreateDir
Const FOF_NOCONFIRMATION = &H10
Const FOF_NOCONFIRMMKDIR = &H200
srcFolder = "C:\WINDOWS\"
destFolder = "C:\_TEST" 'must exist!
'#Copy all files with an 'i' in Windir
'# to a dest folder
ShellCopyFilesFiltered srcFolder, destFolder, "*i*.*", FOF_NOCONFIRMMKDIR
Or FOF_NOCONFIRMATION
Sub ShellCopyFilesFiltered(src, dest, filter, copyFlag)
Const SHCONTF_FOLDERS = 32
Const SHCONTF_NONFOLDERS = 64
Const SHCONTF_INCLUDEHIDDEN = 128
Dim sh
Dim colSrcFiles
Dim oDestFolder
Dim fltFlag
Dim cpyFlag
Set sh = CreateObject("Shell.Application")
Set oDestFolder = sh.NameSpace(dest)
Set colSrcFiles = sh.NameSpace(src).Items()
'All files, no folders
fltFlag = SHCONTF_NONFOLDERS OR SHCONTF_INCLUDEHIDDEN
colSrcFiles.Filter fltFlag, filter
oDestFolder.CopyHere colSrcFiles, copyFlag
End Sub
scott
2007-07-14 16:34:30 UTC
Permalink
CopyHere also accepts a FolderItems-object

Is it possible to use the FolderItems object in a way that 1 CopyHere
statement could be executed and have multiple source folders?

For example:

Copy c:\data1 and c:\data2 to the d:\backup folder with 1 CopyHere
statement?

What I'd like to do with my backup script is copy several folders with one
statement so the progress bar would only appear once and show to total
progress, instead of copying each source folder seperately and showing the
progress bar for each folder.
Post by Alexander Mueller
Post by scott
Is there any way to exclude folders and files when copying with the
Folder.CopyHere method? I want to use the CopyHere method to copy files
because of it's nice progress bar, but need the flexibility of FSO's
similiar copy command.
CODE: **********************
Const FOF_CREATEPROGRESSDLG = &H0&
sParentFolder = "D:\backup"
sFolderSource="c:\data\databases\"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(sParentFolder)
objFolder.CopyHere sFolderSource, FOF_CREATEPROGRESSDLG
Hi
Since CopyHere also accepts a FolderItems-object as
source, you could use its Filter-method of to exclude some items.
However you must apply a filter-mask such as in the windows
filesearch (with * and ? as "jokers"), no explicit list of files to
exclude is accepted.
See sample code below.
MfG,
Alex
'CopyHere Flags YesToAll, AutoCreateDir
Const FOF_NOCONFIRMATION = &H10
Const FOF_NOCONFIRMMKDIR = &H200
srcFolder = "C:\WINDOWS\"
destFolder = "C:\_TEST" 'must exist!
'#Copy all files with an 'i' in Windir
'# to a dest folder
ShellCopyFilesFiltered srcFolder, destFolder, "*i*.*", FOF_NOCONFIRMMKDIR
Or FOF_NOCONFIRMATION
Sub ShellCopyFilesFiltered(src, dest, filter, copyFlag)
Const SHCONTF_FOLDERS = 32
Const SHCONTF_NONFOLDERS = 64
Const SHCONTF_INCLUDEHIDDEN = 128
Dim sh
Dim colSrcFiles
Dim oDestFolder
Dim fltFlag
Dim cpyFlag
Set sh = CreateObject("Shell.Application")
Set oDestFolder = sh.NameSpace(dest)
Set colSrcFiles = sh.NameSpace(src).Items()
'All files, no folders
fltFlag = SHCONTF_NONFOLDERS OR SHCONTF_INCLUDEHIDDEN
colSrcFiles.Filter fltFlag, filter
oDestFolder.CopyHere colSrcFiles, copyFlag
End Sub
Alexander Mueller
2007-07-14 17:29:19 UTC
Permalink
Post by Alexander Mueller
CopyHere also accepts a FolderItems-object
Is it possible to use the FolderItems object in a way that 1 CopyHere
statement could be executed and have multiple source folders?
Copy c:\data1 and c:\data2 to the d:\backup folder with 1 CopyHere
statement?
What I'd like to do with my backup script is copy several folders with one
statement so the progress bar would only appear once and show to total
progress, instead of copying each source folder seperately and showing the
progress bar for each folder.
I don't think its possible with scripting, since - afaics - you can't
create a Namespace/Shellfolder-object or items-collection that is kind of
heterogenous concerning the underlying FSO-folders.

The only exception i know of is that you can shellcopy the
result-list of a file search, cause you can access it as shellnamespace
using some tricks.

Sadly this applies only to files that match some common search
criteria, not to backup-list of random content.

It's possible with pure API (VB,C#,..), where you can add random items to
an ShellFolderItems-Collection.



MfG,
Alex
Paul Randall
2007-07-14 18:45:35 UTC
Permalink
Post by Alexander Mueller
Post by Alexander Mueller
CopyHere also accepts a FolderItems-object
Is it possible to use the FolderItems object in a way that 1 CopyHere
statement could be executed and have multiple source folders?
Copy c:\data1 and c:\data2 to the d:\backup folder with 1 CopyHere
statement?
What I'd like to do with my backup script is copy several folders with one
statement so the progress bar would only appear once and show to total
progress, instead of copying each source folder seperately and showing the
progress bar for each folder.
I don't think its possible with scripting, since - afaics - you can't
create a Namespace/Shellfolder-object or items-collection that is kind of
heterogenous concerning the underlying FSO-folders.
The only exception i know of is that you can shellcopy the
result-list of a file search, cause you can access it as shellnamespace
using some tricks.
Sadly this applies only to files that match some common search
criteria, not to backup-list of random content.
It's possible with pure API (VB,C#,..), where you can add random items to
an ShellFolderItems-Collection.
MfG,
Alex
Hi, Alex
Can you point me to a VBScript that accesses the files & folders in a
file-search result as a shellnamespace?

-Paul Randall
Alexander Mueller
2007-07-14 19:16:59 UTC
Permalink
14.07.2007 20:45, Paul Randall schrieb:

Hi Paul,
Post by Paul Randall
Post by Alexander Mueller
I don't think its possible with scripting, since - afaics - you can't
create a Namespace/Shellfolder-object or items-collection that is kind of
heterogenous concerning the underlying FSO-folders.
The only exception i know of is that you can shellcopy the
result-list of a file search, cause you can access it as shellnamespace
using some tricks.
Hi, Alex
Can you point me to a VBScript that accesses the files & folders in a
file-search result as a shellnamespace?
Yes,

but it's not fully automated, you have to open and run
the search yourself before running the script ...
and the search-window must be left open ...


MfG,
Alex


Option Explicit

Const GUID_FILESEARCH_SHELL_FOLDER = "::{E17D4FC0-5564-11D1-83F2-00A0C90DC849}"

Dim sh
Dim ie
Dim searchItems
Dim item
Dim p
Dim s

Set sh = CreateObject("Shell.Application")
for each ie in sh.Windows
On Error Resume Next
p = ie.Document.Folder.Self.Path
If Err.Number = 0 Then
If 0 = StrComp (p, GUID_FILESEARCH_SHELL_FOLDER, vbTextCompare) Then
Set searchItems = ie.Document.Folder.Items
Exit For
End If
End If

On Error Goto 0
next

If IsObject(searchItems) Then
for each item in searchItems
s = s & item.Path & vbcrlf
next

MsgBox "items found in filesearch window: " & vbcrlf & s

Else
MsgBox "No search window seems to be open ..."
End If
Ruediger Roesler
2007-07-14 22:06:21 UTC
Permalink
Post by Alexander Mueller
I don't think its possible with scripting, since - afaics - you can't
create a Namespace/Shellfolder-object or items-collection that is
kind of heterogenous concerning the underlying FSO-folders.
I think it could be possible, when you take the ShellFolderView-Object.
At first you take an Explorer window, select the folders of the drive
and then you pass the Selected-Items on the colSrcFiles variable.

If you get this object, you can take the ParentFolder of your folders
and select these items:

Const SEL = 1

arrFolder(0) = "c:\data1"
arrFolder(1) = "c:\data2"

Set fso = CreateObject("Scripting.FileSystemObject")
Set xpShell = CreateObject("Shell.Application")

strPaFolder = fso.GetParentFolderName(arrFolder(0))
xpShell.Open strPaFolder
strWndTitle = xpShell.NameSpace(strPaFolder).Title

Set xpViewedFolder = SelectViewedFolder(strWndTitle)

For Each strFolder In arrFolder
For Each xpItem In xpViewedFolder.Folder.Items
If xpItem.IsFolder Then
If xpItem.Name = fso.GetBaseName(strFolder) Then
xpViewedFolder.SelectItem xpItem, SEL
End If
End If
Next
Next

Function SelectViewedFolder(strTitle)
Dim xpWnd, xpFolderView, i

Set xpFolderView = Nothing
Do While (xpFolderView Is Nothing) And (i <= 8) ' wait max 2 s
For Each xpWnd In xpShell.Windows
Set xpFolderView = xpWnd.Document ' is not documented :-)
If Not(xpFolderView Is Nothing) Then
If Not(IsNull(xpFolderView.Folder)) Then
If StrComp(xpFolderView.Folder.Title, strTitle, _
vbTextCompare) = 0 Then
Exit Do ' Folder was found
End If
End If
End If
Next
Wscript.Sleep 250: i = i + 1
Loop

Set SelectViewedFolder = xpFolderView
End Function

Now you can attach these items to your source variable in your function:

Set colSrcFiles = xpViewedFolder.SelectedItems

I would prefer to rename this variable in xpSrcFolderItems or something
like that. :-) But I've no idea, if this order of events is possible,
I've not tested out.

--
ЯR
scott
2007-07-14 23:52:50 UTC
Permalink
I added to your code below, but get the error below. This is getting a bit
over my head, but ideally I'd like create a script that would end with
"d:\backup\data1" and "d:\backup\data2" being copied a created. As I stated
earlier, I can do this using FSO, but I'm trying to do it using Win Shell
Object so I can get 1 windows API progress dialog.


ERROR: *********************

Line: 35
Error: Object doesn't support this property or method: xpFolderView.Folder'

CODE: ********************

Const SEL = 1
iItemCount = 2
redim arrFolder(iItemCount)

arrFolder(0) = "c:\data1"
arrFolder(1) = "c:\data2"

Set fso = CreateObject("Scripting.FileSystemObject")
Set xpShell = CreateObject("Shell.Application")

strPaFolder = fso.GetParentFolderName(arrFolder(0))
xpShell.Open strPaFolder
strWndTitle = xpShell.NameSpace(strPaFolder).Title

Set xpViewedFolder = SelectViewedFolder(strWndTitle)

For Each strFolder In arrFolder
For Each xpItem In xpViewedFolder.Folder.Items
If xpItem.IsFolder Then
If xpItem.Name = fso.GetBaseName(strFolder) Then
xpViewedFolder.SelectItem xpItem, SEL
End If
End If
Next
Next

Function SelectViewedFolder(strTitle)
Dim xpWnd, xpFolderView, i

Set xpFolderView = Nothing
Do While (xpFolderView Is Nothing) And (i <= 8) ' wait max 2 s
For Each xpWnd In xpShell.Windows
Set xpFolderView = xpWnd.Document ' is not documented :-)
If Not(xpFolderView Is Nothing) Then
If Not(IsNull(xpFolderView.Folder)) Then
If StrComp(xpFolderView.Folder.Title, strTitle, _
vbTextCompare) = 0 Then
Exit Do ' Folder was found
End If
End If
End If
Next
Wscript.Sleep 250: i = i + 1
Loop

Set SelectViewedFolder = xpFolderView
End Function


Set colSrcFiles = xpViewedFolder.SelectedItems

sFolderBackup = "d:\backup"

Const FOF_CREATEPROGRESSDLG = &H0&
Dim sh, colSrcFiles,oDestFolder, fltFlag, cpyFlag

Set sh = CreateObject("Shell.Application")
Set oDestFolder = sh.NameSpace(sFolderBackup)

copyFlag = FOF_CREATEPROGRESSDLG
oDestFolder.CopyHere colSrcFiles, copyFlag
Post by Ruediger Roesler
Post by Alexander Mueller
I don't think its possible with scripting, since - afaics - you can't
create a Namespace/Shellfolder-object or items-collection that is
kind of heterogenous concerning the underlying FSO-folders.
I think it could be possible, when you take the ShellFolderView-Object.
At first you take an Explorer window, select the folders of the drive
and then you pass the Selected-Items on the colSrcFiles variable.
If you get this object, you can take the ParentFolder of your folders
Const SEL = 1
arrFolder(0) = "c:\data1"
arrFolder(1) = "c:\data2"
Set fso = CreateObject("Scripting.FileSystemObject")
Set xpShell = CreateObject("Shell.Application")
strPaFolder = fso.GetParentFolderName(arrFolder(0))
xpShell.Open strPaFolder
strWndTitle = xpShell.NameSpace(strPaFolder).Title
Set xpViewedFolder = SelectViewedFolder(strWndTitle)
For Each strFolder In arrFolder
For Each xpItem In xpViewedFolder.Folder.Items
If xpItem.IsFolder Then
If xpItem.Name = fso.GetBaseName(strFolder) Then
xpViewedFolder.SelectItem xpItem, SEL
End If
End If
Next
Next
Function SelectViewedFolder(strTitle)
Dim xpWnd, xpFolderView, i
Set xpFolderView = Nothing
Do While (xpFolderView Is Nothing) And (i <= 8) ' wait max 2 s
For Each xpWnd In xpShell.Windows
Set xpFolderView = xpWnd.Document ' is not documented :-)
If Not(xpFolderView Is Nothing) Then
If Not(IsNull(xpFolderView.Folder)) Then
If StrComp(xpFolderView.Folder.Title, strTitle, _
vbTextCompare) = 0 Then
Exit Do ' Folder was found
End If
End If
End If
Next
Wscript.Sleep 250: i = i + 1
Loop
Set SelectViewedFolder = xpFolderView
End Function
Set colSrcFiles = xpViewedFolder.SelectedItems
I would prefer to rename this variable in xpSrcFolderItems or something
like that. :-) But I've no idea, if this order of events is possible,
I've not tested out.
--
?R
Ruediger Roesler
2007-07-15 02:35:36 UTC
Permalink
Post by scott
I added to your code below, but get the error below. This is getting a
bit over my head, but ideally I'd like create a script that would end
with "d:\backup\data1" and "d:\backup\data2" being copied a created.
As I stated earlier, I can do this using FSO, but I'm trying to do it
using Win Shell Object so I can get 1 windows API progress dialog.
ERROR: *********************
Line: 35
xpFolderView.Folder'
[...]
Post by scott
If Not(IsNull(xpFolderView.Folder)) Then
This should be the line. The folder must exist, and a folder window has
Post by scott
strWndTitle = xpShell.NameSpace(strPaFolder).Title
Do
WScript.Sleep 1000
Loop Until wshShell.AppActivate(strWndTitle)
WScript.Sleep 2000

Additional you've to define the wshShell-Object before:
Set wshShell = CreateObject("Wscript.Shell")
Post by scott
Do While (xpFolderView Is Nothing) And (i <= 8) ' wait max 2 s
I've something changed before in this routine, therefore it is better to
remove the first condition and increase the i-condition for abort to 16
= 4 seconds or some higher value for sure on slow machines, because
it takes more time to display the explorer depending on the system
components. The systems I am working with are from the quicker kind. ;-)

Sorry, but I cannot write the code for you. You have to do some work by
yourself. I'm really sorry! And it is possible that my idea was not so
good.

--
ЯR
scott
2007-07-15 16:55:34 UTC
Permalink
I made your changes below. No errors now, but it still doesn't copy. It does
open an explorer window if it's not open.

I can only assume that the CopyHere function doesn't accept multiple source
files.


UPDATED CODE: ***********************

Const SEL = 1
iItemCount = 2
redim arrFolder(iItemCount)

arrFolder(0) = "c:\data1"
arrFolder(1) = "c:\data2"

Set fso = CreateObject("Scripting.FileSystemObject")
Set xpShell = CreateObject("Shell.Application")
Set wshShell = CreateObject("Wscript.Shell")

strPaFolder = fso.GetParentFolderName(arrFolder(0))
xpShell.Open strPaFolder
strWndTitle = xpShell.NameSpace(strPaFolder).Title

Do
WScript.Sleep 1000
Loop Until wshShell.AppActivate(strWndTitle)
WScript.Sleep 2000

Set xpViewedFolder = SelectViewedFolder(strWndTitle)

For Each strFolder In arrFolder
For Each xpItem In xpViewedFolder.Folder.Items
If xpItem.IsFolder Then
If xpItem.Name = fso.GetBaseName(strFolder) Then
xpViewedFolder.SelectItem xpItem, SEL
End If
End If
Next
Next

Function SelectViewedFolder(strTitle)
Dim xpWnd, xpFolderView, i

Set xpFolderView = Nothing
Do While (xpFolderView Is Nothing) And (i <= 16) ' wait max 2 s
For Each xpWnd In xpShell.Windows
Set xpFolderView = xpWnd.Document ' is not documented :-)
If Not(xpFolderView Is Nothing) Then
If Not(IsNull(xpFolderView.Folder)) Then
If StrComp(xpFolderView.Folder.Title, strTitle, _
vbTextCompare) = 0 Then
Exit Do ' Folder was found
End If
End If
End If
Next
Wscript.Sleep 250: i = i + 1
Loop

Set SelectViewedFolder = xpFolderView
End Function


Set colSrcFiles = xpViewedFolder.SelectedItems

sFolderBackup = "d:\backup"

Const FOF_CREATEPROGRESSDLG = &H0&
Dim sh, colSrcFiles,oDestFolder, fltFlag, cpyFlag

Set sh = CreateObject("Shell.Application")
Set oDestFolder = sh.NameSpace(sFolderBackup)
'Set colSrcFiles = sh.NameSpace(sFolderSource).Items()

copyFlag = FOF_CREATEPROGRESSDLG
oDestFolder.CopyHere colSrcFiles, copyFlag
Post by Ruediger Roesler
Post by scott
I added to your code below, but get the error below. This is getting a
bit over my head, but ideally I'd like create a script that would end
with "d:\backup\data1" and "d:\backup\data2" being copied a created.
As I stated earlier, I can do this using FSO, but I'm trying to do it
using Win Shell Object so I can get 1 windows API progress dialog.
ERROR: *********************
Line: 35
xpFolderView.Folder'
[...]
Post by scott
If Not(IsNull(xpFolderView.Folder)) Then
This should be the line. The folder must exist, and a folder window has
Post by scott
strWndTitle = xpShell.NameSpace(strPaFolder).Title
Do
WScript.Sleep 1000
Loop Until wshShell.AppActivate(strWndTitle)
WScript.Sleep 2000
Set wshShell = CreateObject("Wscript.Shell")
Post by scott
Do While (xpFolderView Is Nothing) And (i <= 8) ' wait max 2 s
I've something changed before in this routine, therefore it is better to
remove the first condition and increase the i-condition for abort to 16
= 4 seconds or some higher value for sure on slow machines, because
it takes more time to display the explorer depending on the system
components. The systems I am working with are from the quicker kind. ;-)
Sorry, but I cannot write the code for you. You have to do some work by
yourself. I'm really sorry! And it is possible that my idea was not so
good.
--
?R
Alexander Mueller
2007-07-15 17:24:02 UTC
Permalink
Post by scott
I made your changes below. No errors now, but it still doesn't copy. It does
open an explorer window if it's not open.
I can only assume that the CopyHere function doesn't accept multiple source
files.
Hi

I'd say: forget it. It's probably not possible using CopyHere.

If you have VB, create your own ShellCopy-ActiveX-DLL, which is not as
much work as it
sounds.

You simply need to wrap the API-function SHFileOperation and allow an
array or
comma-separated list or whatever as src-arg to specify multiple
sources and
convert it to a string that uses NullChars as separators.

See the SHFileOperation + SHFILEOPSTRUCT and the pTo, pFrom
params for details

http://msdn2.microsoft.com/en-us/library/ms647743.aspx
http://msdn2.microsoft.com/en-us/library/ms538322.aspx

MfG,
Alex
scott
2007-07-15 19:16:15 UTC
Permalink
thanks for everyone's help.
Post by Alexander Mueller
Post by scott
I made your changes below. No errors now, but it still doesn't copy. It does
open an explorer window if it's not open.
I can only assume that the CopyHere function doesn't accept multiple source
files.
Hi
I'd say: forget it. It's probably not possible using CopyHere.
If you have VB, create your own ShellCopy-ActiveX-DLL, which is not as
much work as it
sounds.
You simply need to wrap the API-function SHFileOperation and allow an
array or
comma-separated list or whatever as src-arg to specify multiple
sources and
convert it to a string that uses NullChars as separators.
See the SHFileOperation + SHFILEOPSTRUCT and the pTo, pFrom
params for details
http://msdn2.microsoft.com/en-us/library/ms647743.aspx
http://msdn2.microsoft.com/en-us/library/ms538322.aspx
MfG,
Alex
Ruediger Roesler
2007-07-15 22:04:17 UTC
Permalink
Post by scott
thanks for everyone's help.
I've checked it, there is no possibility to copy multiple folders in one
go filtered with the ShellFolder-Object in VBScript. If you are further
interested in this theme, for Visual Basic there is a way described to
program the SHFileOperationStruct:
http://support.microsoft.com/?scid=kb%3Ben-us%3B151799&x=19&y=13

--
ЯR
Alexander Mueller
2007-07-16 07:56:54 UTC
Permalink
Post by Ruediger Roesler
Post by scott
thanks for everyone's help.
I've checked it, there is no possibility to copy multiple folders in one
go filtered with the ShellFolder-Object in VBScript. If you are further
interested in this theme, for Visual Basic there is a way described to
http://support.microsoft.com/?scid=kb%3Ben-us%3B151799&x=19&y=13
Hi Ruediger,


Cool stuff ;-)


MfG,
Alex
Ruediger Roesler
2007-07-16 16:49:42 UTC
Permalink
Post by Alexander Mueller
Cool stuff ;-)
Frankly speaking I've less experience with programming in Visual Basic.

Bye, Alexander!

--
ЯR

Alexander Mueller
2007-07-15 00:16:59 UTC
Permalink
Post by Ruediger Roesler
Post by Alexander Mueller
I don't think its possible with scripting, since - afaics - you can't
create a Namespace/Shellfolder-object or items-collection that is
kind of heterogenous concerning the underlying FSO-folders.
I think it could be possible, when you take the ShellFolderView-Object.
At first you take an Explorer window, select the folders of the drive
and then you pass the Selected-Items on the colSrcFiles variable.
If you get this object, you can take the ParentFolder of your folders
Sorry your script opens a explorer window and selects a specified
folder. Well, nice ;-) that's possible with shell-automation.
If i understood correctly, the OP's effort was to copy files of
different folders (possibly different drives) in one Shell-fileop.

Therefore he needs to pass them as one arg to a CopyHere-call.
Afaik CopyHere takes strings specifying FS-pathes or Shell-objects
of type ShellFolderItems, ShellFolderItem or ShellFolder and
can are convertible to FS-pathes.

I can't see how your sample creates such an ShellFolderItems-collection of
mixed source?
Post by Ruediger Roesler
Set colSrcFiles = xpViewedFolder.SelectedItems
sets a reference to a selection of ShellFolderItems *within the same
folder(view)* or did I miss something?

The problem is that CopyHere is lightweight-wrapper round
SHFileOperation where the possibilty of directly specifying
multisource a/o multidest args was dropped.

MfG,
Alex
Ruediger Roesler
2007-07-15 02:37:56 UTC
Permalink
Post by Alexander Mueller
Sorry your script opens a explorer window and selects a specified
folder. Well, nice ;-) that's possible with shell-automation.
If i understood correctly, the OP's effort was to copy files of
different folders (possibly different drives) in one Shell-fileop.
Yes, it was intentional to build a collection through the
FolderView-object, therefore a folder window must be open.
Post by Alexander Mueller
Therefore he needs to pass them as one arg to a CopyHere-call.
Afaik CopyHere takes strings specifying FS-pathes or Shell-objects
of type ShellFolderItems, ShellFolderItem or ShellFolder and
can are convertible to FS-pathes.
The vItem of the CopyHere-Method is defined as follow:
| Specifies the item or items to copy. This can be a string that
| represents a file name, a FolderItem object, or a FolderItems object.

That is the same data type as the return type of SelectedItems-Method of
the ShellFolderView-Object.
Post by Alexander Mueller
I can't see how your sample creates such an
ShellFolderItems-collection of mixed source?
Post by Ruediger Roesler
Set colSrcFiles = xpViewedFolder.SelectedItems
sets a reference to a selection of ShellFolderItems *within the same
folder(view)* or did I miss something?
According to the SDK it is "oFolderItems =
ShellFolderView.SelectedItems()", that is the same type, I guess, as a
normal FolderItems-Collection.
http://msdn2.microsoft.com/en-US/library/ms630397.aspx
Post by Alexander Mueller
The problem is that CopyHere is lightweight-wrapper round
SHFileOperation where the possibilty of directly specifying
multisource a/o multidest args was dropped.
Yes, is it possible that you are right, it was only a flash of spirit.
Some flashes of this type does not reach the ground. :-) I've warned
against, it was not tested out. In an other context a similar script is
running on machines, but without collecting files between different
folders.

--
ЯR
Continue reading on narkive:
Search results for 'File Copying with Win Shell Object' (Questions and Answers)
10
replies
cheats please???
started 2007-06-06 17:25:13 UTC
video & online games
Loading...