oafcmetty
asked on
Create a folder on a remote server using VBScript
Hi all,
I need to create a folder on a remote server using the FSO in VBScript.
There is a trusted connection between the two servers, however I am running the code on server a, and need it to create the folder on server b before moving to the next step in my process.
I've experimented with the following code:
Sub MakePathRemote(strDirector y, pbHeader)
Dim intLen
Dim intDirLen
Dim objFSORemote
Set objFSORemote = WScript.CreateObject("Scri pting.File SystemObje ct")
If pbHeader Then
WriteToOutFile "Creating Folder on remote server " & strDirectory, True, False
End If
intLen = 4
If Right(strDirectory, 1) <> "\" Then strDirectory = strDirectory + "\"
Do While objFSORemote.FolderExists( strDirecto ry) = False
intDirLen = InStr(intLen, strDirectory, "\")
If objFSORemote.FolderExists( Left(strDi rectory, intDirLen)) = False Then
objFSORemote.CreateFolder Left(strDirectory, intDirLen - 1)
End If
intLen = intDirLen + 1
Loop
End Sub
with the value of strDirectory set as '\\<serverb>\folder' but had no luck. The script runs successfully, but doesn't seem to have created the folder anywhere (not even locally)!
I need to create a folder on a remote server using the FSO in VBScript.
There is a trusted connection between the two servers, however I am running the code on server a, and need it to create the folder on server b before moving to the next step in my process.
I've experimented with the following code:
Sub MakePathRemote(strDirector
Dim intLen
Dim intDirLen
Dim objFSORemote
Set objFSORemote = WScript.CreateObject("Scri
If pbHeader Then
WriteToOutFile "Creating Folder on remote server " & strDirectory, True, False
End If
intLen = 4
If Right(strDirectory, 1) <> "\" Then strDirectory = strDirectory + "\"
Do While objFSORemote.FolderExists(
intDirLen = InStr(intLen, strDirectory, "\")
If objFSORemote.FolderExists(
objFSORemote.CreateFolder Left(strDirectory, intDirLen - 1)
End If
intLen = intDirLen + 1
Loop
End Sub
with the value of strDirectory set as '\\<serverb>\folder' but had no luck. The script runs successfully, but doesn't seem to have created the folder anywhere (not even locally)!
ASKER
No joy I'm afraid...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The script above will create an entire directory tree if it does not exist...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
fozylet - Your script gives me a 'Path not found' error
EDDYKT - I get the following error: "\\<server>:52-Bad file name or number" then "\\<server>\<folder>:76-Pa th not found"
EDDYKT - I get the following error: "\\<server>:52-Bad file name or number" then "\\<server>\<folder>:76-Pa
what is your strDirectory and pbHeader
By the way what is \\<server> and \\<server>\<folder>?
Is it the machine name and folder you want to create? <> is special charater and I don't think you can use it as folder name
By the way what is \\<server> and \\<server>\<folder>?
Is it the machine name and folder you want to create? <> is special charater and I don't think you can use it as folder name
ASKER
Don't worry guys - sorted.
I'm doing it via mapping one of server 2s drives on server 1, and then creating the subfolder that way.
I'm doing it via mapping one of server 2s drives on server 1, and then creating the subfolder that way.
Set objFSORemote = CreateObject("Scripting.Fi
objFSORemote.CreateFolder (strDirectory)
instead of this: Set objFSORemote = WScript.CreateObject("Scri
And then append this towards the bottom...
set objFSO=nothing