Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Enumerating Folders

Reply
 
Old 09-11-2008   #1 (permalink)
RemyMaza


 
 

Enumerating Folders

I'm having a bit of problems with this code and can't seem to get
passed it.



'~~~~~~~~~~~~~~Code~~~~~~~~~~~~~~~


Dim strFolder

strFolder = "C:\test\2008"

set objFSO = createobject("Scripting.FileSystemObject")

GetFolders strFolder

sub GetFolders(byval strDirectory)
set objFolder = objFSO.GetFolder(strDirectory)
for each objFolder in objFolder.SubFolders
Set objFolder = objFSO.CreateFolder(strPath & "\" & "Edcom")
'wscript.echo objFolder.Path
GetFolders objFolder.Path
next
end sub


'~~~~~~~~~~~~~~End~~~~~~~~~~~~~~

What happens when I uncomment the wscript echo, I get a nice prompt
with the correct path of ALL of the sub folders as expected. However,
when I run it trying to create folders using the same logic, I only
create one folder within the 2008 folder. What am I doing wrong?

Thanks,
Matt

My System SpecsSystem Spec
Old 09-11-2008   #2 (permalink)
Al Dunbar


 
 

Re: Enumerating Folders


"RemyMaza" <RemyMaza@xxxxxx> wrote in message
news:3492f357-6ec4-4a4f-ab55-afed1b71a3b3@xxxxxx
Quote:

> I'm having a bit of problems with this code and can't seem to get
> passed it.
>
>
>
> '~~~~~~~~~~~~~~Code~~~~~~~~~~~~~~~
>
>
> Dim strFolder
>
> strFolder = "C:\test\2008"
>
> set objFSO = createobject("Scripting.FileSystemObject")
>
> GetFolders strFolder
>
> sub GetFolders(byval strDirectory)
> set objFolder = objFSO.GetFolder(strDirectory)
> for each objFolder in objFolder.SubFolders
> Set objFolder = objFSO.CreateFolder(strPath & "\" & "Edcom")
> 'wscript.echo objFolder.Path
> GetFolders objFolder.Path
> next
> end sub
>
>
> '~~~~~~~~~~~~~~End~~~~~~~~~~~~~~
>
> What happens when I uncomment the wscript echo, I get a nice prompt
> with the correct path of ALL of the sub folders as expected. However,
> when I run it trying to create folders using the same logic, I only
> create one folder within the 2008 folder. What am I doing wrong?
Your code does not define the variable called strPath.

/Al


My System SpecsSystem Spec
Old 09-11-2008   #3 (permalink)
RemyMaza


 
 

Re: Enumerating Folders

On Sep 11, 1:53*am, "Al Dunbar" <AlanD...@xxxxxx> wrote:
Quote:

> "RemyMaza" <RemyM...@xxxxxx> wrote in message
>
> news:3492f357-6ec4-4a4f-ab55-afed1b71a3b3@xxxxxx
>
>
>
>
>
Quote:

> > I'm having a bit of problems with this code and can't seem to get
> > passed it.
>
Quote:

> > '~~~~~~~~~~~~~~Code~~~~~~~~~~~~~~~
>
Quote:

> > Dim strFolder
>
Quote:

> > strFolder = "C:\test\2008"
>
Quote:

> > set objFSO = createobject("Scripting.FileSystemObject")
>
Quote:

> > GetFolders strFolder
>
Quote:

> > sub GetFolders(byval strDirectory)
> > set objFolder = objFSO.GetFolder(strDirectory)
> > for each objFolder in objFolder.SubFolders
> > Set objFolder = objFSO.CreateFolder(strPath & "\" & "Edcom")
> > 'wscript.echo objFolder.Path
> > GetFolders objFolder.Path
> > next
> > end sub
>
Quote:

> > '~~~~~~~~~~~~~~End~~~~~~~~~~~~~~
>
Quote:

> > What happens when I uncomment the wscript echo, I get a nice prompt
> > with the correct path of ALL of the sub folders as expected. *However,
> > when I run it trying to create folders using the same logic, I only
> > create one folder within the 2008 folder. *What am I doing wrong?
>
> Your code does not define the variable called strPath.
>
> /Al- Hide quoted text -
>
> - Show quoted text -
I see the mistake and have made the change but I'm still not getting
the expected results. When I uncomment the wscript.echo, I see all of
the folders and subfolders and subfolders of the subfolders. When I
activate the folder create code, I get folders in only the first
subfolders. I have these folders within the 2008 directory:
1. New Folder
2. New Folder(2)
3. New Folder(3)

These all get the new folder "Edcom" but their subdirectories do not
even though they are echo'd to me.

'~~~~~~~~~~~~~~Code~~~~~~~~~~~~~~~


Dim strFolder


strFolder = "C:\test\2008"


set objFSO = createobject("Scripting.FileSystemObject")


GetFolders strFolder


sub GetFolders(byval strDirectory)
set objFolder = objFSO.GetFolder(strDirectory)
for each objFolder in objFolder.SubFolders
Set objFolder = objFSO.CreateFolder(objFolder.Path &
"\" & "Edcom")
'wscript.echo objFolder.Path
GetFolders objFolder.Path
next
end sub


'~~~~~~~~~~~~~~End~~~~~~~~~~~~~~


Thanks,
Matt
My System SpecsSystem Spec
Old 09-11-2008   #4 (permalink)
krazymike


 
 

Re: Enumerating Folders

Dim strFolder

strFolder = "C:\test\2008\"

set objFSO = createobject("Scripting.FileSystemObject")

GetFolders strFolder
Sub getFolders(patH)
Dim f, fs
Set fs = objFSO.GetFolder(patH)
For Each f In fs.Folders
objFSO.CreateFolder (patH & f.Name & "\")
Call getFolders(patH & f.Name & "\")
Next f
End Sub
My System SpecsSystem Spec
Old 09-11-2008   #5 (permalink)
krazymike


 
 

Re: Enumerating Folders

Sorry, I didn't finish customizing my code. It's from a different
script.

strFolder = "C:\tempy\"
set objFSO = createobject("Scripting.FileSystemObject")
GetFolders strFolder

Sub getFolders(patH)
Dim f, fs
'msgbox path
Set fs = objFSO.GetFolder(patH)
For Each f In fs.subFolders
if not objFSO.FolderExists(path & "\Edcom") then
objFSO.CreateFolder (patH & "\Edcom")
Call getFolders(patH & f.Name & "\")
Next
End Sub
My System SpecsSystem Spec
Old 09-11-2008   #6 (permalink)
Mike


 
 

Re: Enumerating Folders

Krazymike is having a rough day.

strFolder = "C:\tempy\"

set objFSO = createobject("Scripting.FileSystemObject")

GetFolders strFolder

if not objFSO.FolderExists(strfolder & "\Edcom") then objFSO.CreateFolder
(strfolder & "\Edcom")

Sub getFolders(patH)
Dim f, fs
'msgbox path
Set fs = objFSO.GetFolder(patH)
For Each f In fs.subFolders
if f.name <> "Edcom" then
if not objFSO.FolderExists(f.path & "\Edcom") then
objFSO.CreateFolder (f.patH & "\Edcom")
Call getFolders(patH & f.Name & "\")
end if
Next
End Sub

"RemyMaza" <RemyMaza@xxxxxx> wrote in message
news:16e937fc-b94f-40ed-b37b-de46a679b195@xxxxxx
On Sep 11, 1:53 am, "Al Dunbar" <AlanD...@xxxxxx> wrote:
Quote:

> "RemyMaza" <RemyM...@xxxxxx> wrote in message
>
> news:3492f357-6ec4-4a4f-ab55-afed1b71a3b3@xxxxxx
>
>
>
>
>
Quote:

> > I'm having a bit of problems with this code and can't seem to get
> > passed it.
>
Quote:

> > '~~~~~~~~~~~~~~Code~~~~~~~~~~~~~~~
>
Quote:

> > Dim strFolder
>
Quote:

> > strFolder = "C:\test\2008"
>
Quote:

> > set objFSO = createobject("Scripting.FileSystemObject")
>
Quote:

> > GetFolders strFolder
>
Quote:

> > sub GetFolders(byval strDirectory)
> > set objFolder = objFSO.GetFolder(strDirectory)
> > for each objFolder in objFolder.SubFolders
> > Set objFolder = objFSO.CreateFolder(strPath & "\" & "Edcom")
> > 'wscript.echo objFolder.Path
> > GetFolders objFolder.Path
> > next
> > end sub
>
Quote:

> > '~~~~~~~~~~~~~~End~~~~~~~~~~~~~~
>
Quote:

> > What happens when I uncomment the wscript echo, I get a nice prompt
> > with the correct path of ALL of the sub folders as expected. However,
> > when I run it trying to create folders using the same logic, I only
> > create one folder within the 2008 folder. What am I doing wrong?
>
> Your code does not define the variable called strPath.
>
> /Al- Hide quoted text -
>
> - Show quoted text -
I see the mistake and have made the change but I'm still not getting
the expected results. When I uncomment the wscript.echo, I see all of
the folders and subfolders and subfolders of the subfolders. When I
activate the folder create code, I get folders in only the first
subfolders. I have these folders within the 2008 directory:
1. New Folder
2. New Folder(2)
3. New Folder(3)

These all get the new folder "Edcom" but their subdirectories do not
even though they are echo'd to me.

'~~~~~~~~~~~~~~Code~~~~~~~~~~~~~~~


Dim strFolder


strFolder = "C:\test\2008"


set objFSO = createobject("Scripting.FileSystemObject")


GetFolders strFolder


sub GetFolders(byval strDirectory)
set objFolder = objFSO.GetFolder(strDirectory)
for each objFolder in objFolder.SubFolders
Set objFolder = objFSO.CreateFolder(objFolder.Path &
"\" & "Edcom")
'wscript.echo objFolder.Path
GetFolders objFolder.Path
next
end sub


'~~~~~~~~~~~~~~End~~~~~~~~~~~~~~


Thanks,
Matt


My System SpecsSystem Spec
Old 09-11-2008   #7 (permalink)
krazymike


 
 

Re: Enumerating Folders

Thank you!! I am.
My System SpecsSystem Spec
Old 09-11-2008   #8 (permalink)
RemyMaza


 
 

Re: Enumerating Folders

On Sep 11, 2:05*pm, "Mike" <nos...@xxxxxx> wrote:
Quote:

> Krazymike is having a rough day.
>
> strFolder = "C:\tempy\"
>
> set objFSO = createobject("Scripting.FileSystemObject")
>
> GetFolders strFolder
>
> if not objFSO.FolderExists(strfolder & "\Edcom") then objFSO.CreateFolder
> (strfolder & "\Edcom")
>
> Sub getFolders(patH)
> * * *Dim f, fs
> * * *'msgbox path
> * * *Set fs = objFSO.GetFolder(patH)
> * * *For Each f In fs.subFolders
> * * * * *if f.name <> "Edcom" then
> * * * * *if not objFSO.FolderExists(f.path & "\Edcom") then
> objFSO.CreateFolder (f.patH & "\Edcom")
> * * * * * * * Call getFolders(patH & f.Name & "\")
> * * * * end if
> * * Next
> End Sub
>
> "RemyMaza" <RemyM...@xxxxxx> wrote in message
>
> news:16e937fc-b94f-40ed-b37b-de46a679b195@xxxxxx
> On Sep 11, 1:53 am, "Al Dunbar" <AlanD...@xxxxxx> wrote:
>
>
>
>
>
Quote:

> > "RemyMaza" <RemyM...@xxxxxx> wrote in message
>
Quote:

> >news:3492f357-6ec4-4a4f-ab55-afed1b71a3b3@xxxxxx
>
Quote:
Quote:

> > > I'm having a bit of problems with this code and can't seem to get
> > > passed it.
>
Quote:
Quote:

> > > '~~~~~~~~~~~~~~Code~~~~~~~~~~~~~~~
>
Quote:
Quote:

> > > Dim strFolder
>
Quote:
Quote:

> > > strFolder = "C:\test\2008"
>
Quote:
Quote:

> > > set objFSO = createobject("Scripting.FileSystemObject")
>
Quote:
Quote:

> > > GetFolders strFolder
>
Quote:
Quote:

> > > sub GetFolders(byval strDirectory)
> > > set objFolder = objFSO.GetFolder(strDirectory)
> > > for each objFolder in objFolder.SubFolders
> > > Set objFolder = objFSO.CreateFolder(strPath & "\" & "Edcom")
> > > 'wscript.echo objFolder.Path
> > > GetFolders objFolder.Path
> > > next
> > > end sub
>
Quote:
Quote:

> > > '~~~~~~~~~~~~~~End~~~~~~~~~~~~~~
>
Quote:
Quote:

> > > What happens when I uncomment the wscript echo, I get a nice prompt
> > > with the correct path of ALL of the sub folders as expected. However,
> > > when I run it trying to create folders using the same logic, I only
> > > create one folder within the 2008 folder. What am I doing wrong?
>
Quote:

> > Your code does not define the variable called strPath.
>
Quote:

> > /Al- Hide quoted text -
>
Quote:

> > - Show quoted text -
>
> I see the mistake and have made the change but I'm still not getting
> the expected results. *When I uncomment the wscript.echo, I see all of
> the folders and subfolders and subfolders of the subfolders. *When I
> activate the folder create code, I get folders in only the first
> subfolders. *I have these folders within the 2008 directory:
> 1. New Folder
> 2. New Folder(2)
> 3. New Folder(3)
>
> These all get the new folder "Edcom" but their subdirectories do not
> even though they are echo'd to me.
>
> '~~~~~~~~~~~~~~Code~~~~~~~~~~~~~~~
>
> Dim strFolder
>
> strFolder = "C:\test\2008"
>
> set objFSO = createobject("Scripting.FileSystemObject")
>
> GetFolders strFolder
>
> sub GetFolders(byval strDirectory)
> * * * * set objFolder = objFSO.GetFolder(strDirectory)
> * * * * for each objFolder in objFolder.SubFolders
> * * * * * * * * Set objFolder = objFSO.CreateFolder(objFolder.Path &
> "\" & "Edcom")
> * * * * * * * * 'wscript.echo objFolder.Path
> * * * * * * * * GetFolders objFolder.Path
> * * * * next
> end sub
>
> '~~~~~~~~~~~~~~End~~~~~~~~~~~~~~
>
> Thanks,
> Matt- Hide quoted text -
>
> - Show quoted text -
That looks like hotness. I'll try it tonight. THANKS to all!

Cheers,
Matt
My System SpecsSystem Spec
Old 09-11-2008   #9 (permalink)
RemyMaza


 
 

Re: Enumerating Folders

On Sep 11, 2:05*pm, "Mike" <nos...@xxxxxx> wrote:
Quote:

> Krazymike is having a rough day.
>
> strFolder = "C:\tempy\"
>
> set objFSO = createobject("Scripting.FileSystemObject")
>
> GetFolders strFolder
>
> if not objFSO.FolderExists(strfolder & "\Edcom") then objFSO.CreateFolder
> (strfolder & "\Edcom")
>
> Sub getFolders(patH)
> * * *Dim f, fs
> * * *'msgbox path
> * * *Set fs = objFSO.GetFolder(patH)
> * * *For Each f In fs.subFolders
> * * * * *if f.name <> "Edcom" then
> * * * * *if not objFSO.FolderExists(f.path & "\Edcom") then
> objFSO.CreateFolder (f.patH & "\Edcom")
> * * * * * * * Call getFolders(patH & f.Name & "\")
> * * * * end if
> * * Next
> End Sub
>
> "RemyMaza" <RemyM...@xxxxxx> wrote in message
>
> news:16e937fc-b94f-40ed-b37b-de46a679b195@xxxxxx
> On Sep 11, 1:53 am, "Al Dunbar" <AlanD...@xxxxxx> wrote:
>
>
>
>
>
Quote:

> > "RemyMaza" <RemyM...@xxxxxx> wrote in message
>
Quote:

> >news:3492f357-6ec4-4a4f-ab55-afed1b71a3b3@xxxxxx
>
Quote:
Quote:

> > > I'm having a bit of problems with this code and can't seem to get
> > > passed it.
>
Quote:
Quote:

> > > '~~~~~~~~~~~~~~Code~~~~~~~~~~~~~~~
>
Quote:
Quote:

> > > Dim strFolder
>
Quote:
Quote:

> > > strFolder = "C:\test\2008"
>
Quote:
Quote:

> > > set objFSO = createobject("Scripting.FileSystemObject")
>
Quote:
Quote:

> > > GetFolders strFolder
>
Quote:
Quote:

> > > sub GetFolders(byval strDirectory)
> > > set objFolder = objFSO.GetFolder(strDirectory)
> > > for each objFolder in objFolder.SubFolders
> > > Set objFolder = objFSO.CreateFolder(strPath & "\" & "Edcom")
> > > 'wscript.echo objFolder.Path
> > > GetFolders objFolder.Path
> > > next
> > > end sub
>
Quote:
Quote:

> > > '~~~~~~~~~~~~~~End~~~~~~~~~~~~~~
>
Quote:
Quote:

> > > What happens when I uncomment the wscript echo, I get a nice prompt
> > > with the correct path of ALL of the sub folders as expected. However,
> > > when I run it trying to create folders using the same logic, I only
> > > create one folder within the 2008 folder. What am I doing wrong?
>
Quote:

> > Your code does not define the variable called strPath.
>
Quote:

> > /Al- Hide quoted text -
>
Quote:

> > - Show quoted text -
>
> I see the mistake and have made the change but I'm still not getting
> the expected results. *When I uncomment the wscript.echo, I see all of
> the folders and subfolders and subfolders of the subfolders. *When I
> activate the folder create code, I get folders in only the first
> subfolders. *I have these folders within the 2008 directory:
> 1. New Folder
> 2. New Folder(2)
> 3. New Folder(3)
>
> These all get the new folder "Edcom" but their subdirectories do not
> even though they are echo'd to me.
>
> '~~~~~~~~~~~~~~Code~~~~~~~~~~~~~~~
>
> Dim strFolder
>
> strFolder = "C:\test\2008"
>
> set objFSO = createobject("Scripting.FileSystemObject")
>
> GetFolders strFolder
>
> sub GetFolders(byval strDirectory)
> * * * * set objFolder = objFSO.GetFolder(strDirectory)
> * * * * for each objFolder in objFolder.SubFolders
> * * * * * * * * Set objFolder = objFSO.CreateFolder(objFolder.Path &
> "\" & "Edcom")
> * * * * * * * * 'wscript.echo objFolder.Path
> * * * * * * * * GetFolders objFolder.Path
> * * * * next
> end sub
>
> '~~~~~~~~~~~~~~End~~~~~~~~~~~~~~
>
> Thanks,
> Matt- Hide quoted text -
>
> - Show quoted text -
Works like a charm... Thank you very much.

Matt
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Enumerating IIS 6 App Pools PowerShell
Enumerating Uninstall Key from Registry PowerShell
Enumerating the Registry... Vista General
Enumerating group membership & ADSI PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46