hi

I need to create a directory foldername\foldername1\foldername2 under the parent directory
the parent directory c:\docs and settings\<user profile>\application data\microsoft\ foldername\foldername1\foldername2
only need to create it if it does not exist
any pointers please as to where I can get a vbscript to do this
cheers
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
Are you serious?!? There must be 1000s on the web. Take a look here http://www.devguru.com/utilities/search.asp and enter 'FileSystemObject' as your search term.
Answered 09/12/2007 by: VBScab
Red Belt

Please log in to comment
0
How about a DOS command:

mkdir "%AppData%\microsoft\foldername\foldername1\foldername2"

---> Obviously i'm too tired, now i see you asked for VBS code
Answered 09/12/2007 by: gmorgan618
Blue Belt

Please log in to comment
0
thanks it msut be me I just could not find anything
Answered 09/12/2007 by: cygan
Fifth Degree Brown Belt

Please log in to comment
0
http://www.computerperformance.co.uk/vbscript/vbscript_folder_create.htm

But use an If...Then statement to create a condition that either creates the directory or doesn't.

example: If Not objFSO.FolderExists(whatever your variable is for your folder path) then
objFSO.CreateFolder(whatever your variable is for your folder path)
End if
Answered 09/12/2007 by: danr29
Purple Belt

Please log in to comment
0
You can do it the long or short (recursion function) way.


Dim WSHShell : Set WSHShell = CreateObject("WScript.Shell")
Dim sAPPDATA : sAPPDATA = WSHShell.Environment("Volatile").Item ("APPDATA")
Dim Path : Path = sAPPDATA & "\Microsoft\foldername\foldername1\foldername2"

'// a normal function
Call CreateDirectoryPath(Path)

'// a recursion function
Call Recursion(Path)

Function CreateDirectoryPath(DirPath)
Dim FSO, aDirectories, sCreateDirectory, iDirectory

Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FolderExists(DirPath) Then
Exit Function
End If

aDirectories = Split(DirPath, "\")
sCreateDirectory = aDirectories(0)
For iDirectory = 1 To UBound(aDirectories)
sCreateDirectory = sCreateDirectory & "\" & aDirectories(iDirectory)
If Not FSO.FolderExists(sCreateDirectory) Then
FSO.CreateFolder(sCreateDirectory)
End If
Next
End Function

Function Recursion(DirectoryPath)
Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")

If FSO.FolderExists(DirectoryPath) Then Exit Function
Call Recursion(FSO.GetParentFolderName(DirectoryPath))
FSO.CreateFolder(DirectoryPath)
End Function
Answered 09/12/2007 by: AngelD
Red Belt

Please log in to comment
0
Kim, I believe that CreateFolder will jump right in and create the whole path without the need (as you would expect in DOS) to create the parents first.
Answered 09/13/2007 by: VBScab
Red Belt

Please log in to comment
0
Did a quick test and doesn't seem to be so (Microsoft VBScript runtime error: Path not found).


Dim WSHShell : Set WSHShell = CreateObject("WScript.Shell")
Dim sAPPDATA : sAPPDATA = WSHShell.Environment("Volatile").Item ("APPDATA")
Dim Path : Path = sAPPDATA & "\Microsoft\foldername\foldername1\foldername2"

Call MkDir(Path)

Function MkDir(DirectoryPath)
Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CreateFolder(DirectoryPath)
End Function
Answered 09/13/2007 by: AngelD
Red Belt

Please log in to comment
0
Cool. As ever, HTBC
Answered 09/13/2007 by: VBScab
Red Belt

Please log in to comment
0
Hi cygan,
are you intend to use this script with CA in a MSI?
If yes, a more robust alternative would be, to use the Directory and CreateFolder tables in the MSI.
Regards, Nick
Answered 09/13/2007 by: nheim
Tenth Degree Black Belt

Please log in to comment
Answer this question or Comment on this question for clarity