/build/static/layout/Breadcrumb_cap_w.png

CREATE A DIRECTORY USING VBSCRIPT

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

Answers (9)

Posted by: anonymous_9363 17 years ago
Red Belt
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.
Posted by: gmorgan618 17 years ago
Blue Belt
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
Posted by: cygan 17 years ago
Fifth Degree Brown Belt
0
thanks it msut be me I just could not find anything
Posted by: danr29 17 years ago
Purple Belt
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
Posted by: AngelD 17 years ago
Red Belt
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
Posted by: anonymous_9363 17 years ago
Red Belt
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.
Posted by: AngelD 17 years ago
Red Belt
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
Posted by: anonymous_9363 17 years ago
Red Belt
0
Cool. As ever, HTBC
Posted by: nheim 17 years ago
10th Degree Black Belt
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
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ