lauraSatellite
Technical User
Hi, im altering a script that creates a specifically named folder:
Sub CreateFolders(strPath)
Dim objFso
Dim arrFolders
Dim strDrive
Dim strFolder
Set objFso = CreateObject("Scripting.FileSystemObject")
' Format path (remove leading and trailing spaces, and final backslash)
strPath = Trim(strPath)
If Right(strPath, 1) = "\" Then
strPath = Left(strPath, Len(strPath) - 1)
End If
' Check that a drive is specified and that it exists (if not, exit sub)
If Mid(strPath, 2, 2) <> ":\" Then
WScript.Echo "The path specified is invalid."
Exit Sub
Else
strDrive = Left(strPath, 1)
If Not objFso.DriveExists(strDrive) Then
WScript.Echo "The drive specified does not exist."
Exit Sub
End If
End If
' Split the path into an array, first element is the drive, subsequent elements are the folders
arrFolders = Split(strPath, "\")
' Build the path, folder by folder. If folder doesn't exist, create it
strFolder = arrFolders(0)
For i = LBound(arrFolders) To UBound(arrFolders) - 1
strFolder = strFolder & "\" & arrFolders(i+1)
If Not objFso.FolderExists(strFolder) Then
objFso.CreateFolder(strFolder)
End If
Next
End Sub
If the param strPath is set to "C:\theNewFolder" the script works fine.
I have been tryin to create a folder named according to the date and time. I tried:
strDateTime = FormatDateTime(now, 3)
strPathParam = "C:\" & strDateTime
CreateFolders strPathParam
The following error is returned:
Line:38
Char:1
Error: Invalid procedure call or argument
Code: 800A0005
Source: MS VBS runtime error
Anyone have any ideas as to what im doing wrong?
I know it must be something small but its driving me dotty..
Sub CreateFolders(strPath)
Dim objFso
Dim arrFolders
Dim strDrive
Dim strFolder
Set objFso = CreateObject("Scripting.FileSystemObject")
' Format path (remove leading and trailing spaces, and final backslash)
strPath = Trim(strPath)
If Right(strPath, 1) = "\" Then
strPath = Left(strPath, Len(strPath) - 1)
End If
' Check that a drive is specified and that it exists (if not, exit sub)
If Mid(strPath, 2, 2) <> ":\" Then
WScript.Echo "The path specified is invalid."
Exit Sub
Else
strDrive = Left(strPath, 1)
If Not objFso.DriveExists(strDrive) Then
WScript.Echo "The drive specified does not exist."
Exit Sub
End If
End If
' Split the path into an array, first element is the drive, subsequent elements are the folders
arrFolders = Split(strPath, "\")
' Build the path, folder by folder. If folder doesn't exist, create it
strFolder = arrFolders(0)
For i = LBound(arrFolders) To UBound(arrFolders) - 1
strFolder = strFolder & "\" & arrFolders(i+1)
If Not objFso.FolderExists(strFolder) Then
objFso.CreateFolder(strFolder)
End If
Next
End Sub
If the param strPath is set to "C:\theNewFolder" the script works fine.
I have been tryin to create a folder named according to the date and time. I tried:
strDateTime = FormatDateTime(now, 3)
strPathParam = "C:\" & strDateTime
CreateFolders strPathParam
The following error is returned:
Line:38
Char:1
Error: Invalid procedure call or argument
Code: 800A0005
Source: MS VBS runtime error
Anyone have any ideas as to what im doing wrong?
I know it must be something small but its driving me dotty..