|
-
May 28th, 2010, 08:04 AM
#76
Re: Loop through folders with shell object.
Thank you. 
I got a like of the shell32 objects meanwhile. They are rather flexible and shell32.shell is a fast executing thing with everything concerning folder and folderitems (also files).
Unfortunately I was not able to get CreateObject() produce any of the shell32 objects, so it seems late binding and use in VBScript is out of scope. Except I did something wrong.
Anyway I don't understand it fully:
I can use CreateObject("WScript.Shell") to get a scripting shell.
I get an FSO by using CreateObject("Scripting.FileSystemObject")
both objects are provided by "scrrun.dll"
I can make a Recordset with CreateObject("ADODB.Recordset") anytime. It is from an "msadoxx.dll".
I cannot, however CreateObject("Shell32.FolderItem"). The object is defined in "shell32.dll", but seems not to be registered under this name.
Maybe I only don't know the right name to precede, like ADODB for objects from the msado15.dll...
Making a reference to shell32.dll ('Microsoft Shell Controls and Automation), however, suffices all needs and gives you intellisense and F2 object browser to learn more about the provided objects.
-
May 28th, 2010, 10:45 AM
#77
Re: Loop through folders with shell object.
Well I can get this to not fail in creating an object...
Code:
Dim O As Object
Set O = CreateObject("Shell.Application")
But it returns a never ending tree of application and parent references, meaning, if you looked in the locals window you would see...
Code:
-Application
-Application
-Application
+Application
-Parent
-Parent
-Parent
+Parent
So it is pretty much worthless. I also tried with create object...
shellfolderitem/view
shell.shellfolderitem/view
shell32.shellfolderitem/view
ishell.shellfolderitem/view
ishell32.shellfolderitem/view
shell.folderitem/view
ishell.folderitem/view
shell32.folderitem/view
ishell32.folderitem/view
/ = (folderitem and folderview)
also shell.parent does not work...
So we are definitly missing something or since it is the shell32.dll and we see it a lot in API's, it may not be fully com compliant...
Just a guess...
-
May 28th, 2010, 12:03 PM
#78
Re: Loop through folders with shell object.
Have you tried anything like this...
Code:
function fnCreateFolder()
dim oShell
dim oFolder
dim sDir
sDir = "C:\SomePath"
set oShell = CreateObject("shell.Shell_Application")
set oFolder = oShell.NameSpace(sDir)
end function
http://msdn.microsoft.com/en-us/libr...90(VS.85).aspx
Always use [code][/code] tags when posting code.
-
May 28th, 2010, 10:12 PM
#79
Re: Loop through folders with shell object.
WoF, I think the miser of data has it in that link...
-
June 1st, 2010, 08:14 AM
#80
Re: Loop through folders with shell object.
This looks very promising.
Only the statement
set oShell = CreateObject("shell.Shell_Application")
gives an error on my system. It cannot create the object.
Anybody actually tried it?
-
June 2nd, 2010, 12:14 AM
#81
Re: Loop through folders with shell object.
Now that you mention this problem I gave it a try on vista home and I get an error on that line also. I'm guessing this quote should be more explanatory...
[quote]
You can also instantiate many of the Shell objects with late binding. This approach works in Visual Basic applications and in script. The following example shows how to instantiate the Shell object in JScript.
Which by exclusion means one cannot do it via VB6.0... I guess???
-
June 2nd, 2010, 09:59 AM
#82
Re: Loop through folders with shell object.
No. I tried it in a vbs script file. Put this into a file texst.vbs
Code:
dim shl
set shl=CreateObject("shell.Shell_Application")
and duble click to run it.
It shows the same automation error as if you'd use it in VB6.
As for COM compliance, if the objects in shell32.dll were not COM conform, you wouldn't be able to add a reference to the dll and get objects descriptions in the object browser.
-
June 2nd, 2010, 10:57 AM
#83
Re: Loop through folders with shell object.
That's odd. You would think the info on MSDN would be accurate, maybe it only works under IIS?
Always use [code][/code] tags when posting code.
-
June 2nd, 2010, 03:25 PM
#84
Re: Loop through folders with shell object.
 Originally Posted by WoF
No. I tried it in a vbs script file. Put this into a file texst.vbs
Code:
dim shl
set shl=CreateObject("shell.Shell_Application")
and duble click to run it.
It shows the same automation error as if you'd use it in VB6.
As for COM compliance, if the objects in shell32.dll were not COM conform, you wouldn't be able to add a reference to the dll and get objects descriptions in the object browser.
Running as ADMIN?
-
June 3rd, 2010, 10:45 AM
#85
Re: Loop through folders with shell object.
Yes.
Saying: ActiveX component cannot create object: 'shell.Shell_Application'
I read all the MSDN article about this and should think it would work...
-
June 3rd, 2010, 11:29 AM
#86
Re: Loop through folders with shell object.
That's wierd I copied the html code from the MSDN site that shows the usage of several of the shell objects and every one of them generates an error on my system XP Sp3, IE 8. I wonder if it could be related to internet settings?
Always use [code][/code] tags when posting code.
-
June 4th, 2010, 01:08 AM
#87
Re: Loop through folders with shell object.
Well I do know that Shell.Application works...
Code:
Dim O As Object
Dim Ds As Object
Dim D As Object
Dim I As Integer
Set O = CreateObject("shell.application")
Set Ds = O.namespace("c:\") 'I wonder if ssfDesktop constant value would work here...
MsgBox Ds.Title
'the above works but below does not... see locals window...
Set D = Ds.self.getfolder("C:\")
-
June 4th, 2010, 10:15 AM
#88
Re: Loop through folders with shell object.
Good finding vb5. How did you come by that? Is that somewhere in MSDN
In opposite to "shell.Shell_Application" the string "shell.application" works and a shell32 shell object is created.
As soon as you have a shell, the .Namespace method will return a shell32 Folder object, and there we are.
All ready for the late binding scan-all-your-folders-as-fast-as-you-can.
BTW.: The special folder constants are not known automatically when a shell is late bound, but if you know that ssdDesktop is 0 you can as well: Set Ds=O.Namespace(0)
Last edited by WoF; June 4th, 2010 at 10:26 AM.
-
June 4th, 2010, 10:24 AM
#89
Re: Loop through folders with shell object.
Concerning the Set D = Ds.self.getfolder("C:\") I found this:
The Namespace() method does not return a FolderItem object, but a Folder3 object which has no GetFolder method, so the statement fails.
Instead, this object IS already a Folder structure. It will contain a collection of FolderItems which you can scan like
Code:
For Each fit in DS.Items
If fit.IsFolder then use fit.GetFolder for recursive scanning
Next
The GetFolder property is only available on the FolderItem object.
Last edited by WoF; June 4th, 2010 at 06:16 PM.
-
June 5th, 2010, 02:34 AM
#90
Re: Loop through folders with shell object.
No, that is from my earlier post in playing around with the create object if you remember the listing of things I tried that failed and then rereading the other code posted by you to get that far. However, in this thread from another forum, we have more information... http://www.vbforums.com/showthread.php?p=3815897 and from what you implied WoF, we might have a solution but presently I'm getting stuck when passing a variable to be used in the namespace(arguement)...
Code:
Option Explicit
Dim ShellObject As Object
Private Sub Form_Load()
Set ShellObject = CreateObject("shell.application")
ScanDir "C:\a\"
End Sub
Public Sub ScanDir(DirToScan As String)
Dim FolderCollection As Object
Dim SingleFolder As Object
Set FolderCollection = ShellObject.namespace(DirToScan) 'this fails but when i hard code "c:\a\" it works???
For Each SingleFolder In FolderCollection.items
If SingleFolder.isfolder Then
'ScanDir SingleFolder.Name 'which means I cannot do this for the recursive call
Debug.Print "Found Folder: " & SingleFolder.Name
Else
Debug.Print "Found File: " & SingleFolder.Name
End If
Next
End Sub
So I am obviously doing something wrong which I don't see at the moment or something else is up. I don't know??? I'll play around with it some more but some fresh eyes would not hurt either...
Okay: Have update...
'this works
Set FolderCollection = ShellObject.namespace("C:\") 'works
'these do not...
Set FolderCollection = ShellObject.namespace(PathToSearch)
Set FolderCollection = ShellObject.namespace(StrPtr(PathToSearch))
Set FolderCollection = ShellObject.namespace(VarPtr(PathToSearch))
Set FolderCollection = ShellObject.namespace("""" & PathToSearch & """")
a conundrum for me at the moment...
Last edited by vb5prgrmr; June 5th, 2010 at 09:32 AM.
Reason: Update
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|