Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recursive depth 1 level create directory 1

Status
Not open for further replies.

hovercraft

Technical User
Jun 19, 2006
236
US
Greetings folk,

I'm stuck trying to run a vbs in the same directory that contains a folder called "reports". In the reports directory there are hundreds of sub-directories. I'm trying create a directory in each of the hundreds of sub-directories, called "archive". This is the code I'm using but it doesn't seem to do anything. The cmd window pops up but then is quickly gone. Any ideas? thanks!

Code:
Dim mynewdir

Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubfolders FSO.GetFolder("reports\"), 1

Sub ShowSubFolders(Folder, Depth)
    If Depth > 0 then
        For Each Subfolder in Folder.SubFolders
			mynewdir =  Subfolder.Path & "\archive\"
			set mynewdir = FSO.CreateDirectory(mynewdir)
            ShowSubFolders Subfolder, Depth -1 
        Next
    End if
End Sub
 
Why not simply this ?
Code:
Set FSO = CreateObject("Scripting.FileSystemObject")
For Each Subfolder In FSO.GetFolder("\path\to\reports").SubFolders
  FSO.CreateDirectory Subfolder.Path & "\archive"
Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you PHV. I've tried your suggestion but am receiving an "Object doesn't support this property or method: CreateDirectory" error.

My full path has a folder for a website with the dots in it's name. Such as, D:\websites\
I'm wondering if that has anything to do with it.
 
Sorry for the typo:
FSO.CreateFolder Subfolder.Path & "\archive"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Totally my fault! If I had just checked the method instead of assuming Create "Directory" would work vs Create "Folder" I wouldn't have had to ask for assistance.

Thank You Thank You Thank You!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top