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
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)
Please log in to answer
Posted by:
anonymous_9363
17 years ago
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
Posted by:
danr29
17 years ago
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
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
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
Posted by:
AngelD
17 years ago
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:
nheim
17 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.