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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How create more then 1 (sub)folder ? 2

Status
Not open for further replies.

bojzon

IS-IT--Management
Sep 18, 2003
25
SI
I need to create with FileSystemObject from
D:\ MyFolder\ subFolder1\subFolder2\subFolder3
the same structure subfolders to
C:\ Backup\ MyFolder\ subFolder1\subFolder2\subFolder3

I get Run time error 76 – Path not found – (Respecify the path) for code line :fso.CreateFolder (fol)-(The same Error receive when using MkDir (fol))

CODE:
Sub CreateFolder()
Dim fso
Dim fol As String

fol = "d:\MyFolder\subFolder1\subFolder2\subFolder3"
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(fol) Then
fso.CreateFolder (fol)
.....
Any suggestion?

Thanks
Bojzon

 
Something like this ?
Source = "D:\MyFolder\subFolder1\subFolder2\subFolder3"
Target = "C:\Backup"
a = Split(Source, "\")
a(0) = Target
myDir = ""
Set fso = CreateObject("Scripting.FileSystemObject")
For i = 0 To Ubound(a)
myDir = myDir & a(i)
If Not fso.FolderExists(myDir) Then _
fso.CreateFolder(myDir)
myDir = myDir & "\"
Next

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top