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 RoeslerPost by Alexander MuellerI 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