How to create a folder using VB Script

Hi All,

I need to create an additional folder in the Documents folder called "SharePoint" using an existing  VB script. I am pretty much new to VB , but this will be a logon script using Group Policy. I pretty much can do this using a batch file by UNC (\\servername\users$\%username%\documents\Sharepoint ).

Can this be done using the existing VB Script ?

Moey
Moey_GAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
Yes, as long as you have permissions you can do this using something like this example:

Function CreateFolderDemo
   Dim fso, f
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.CreateFolder("c:\New Folder")
   CreateFolderDemo = f.Path
End Function

Reference is here:

http://msdn.microsoft.com/en-us/library/7kby5ae3(v=VS.85).aspx

~bp
0
merowingerCommented:
I assume this are you homedrive folder for the users on a server.
Sou you could execute the following script one time directly on the server to create the sharepoint folder in each user folder:
Set objFSO = CreateObject("Scripting.FileSystemObject")
set objFolder = objFSO.GetFolder("D:\Users")

'Now loop throught each user folder
For each subfolder in objFolder.SubFolders
	objFSO.CreateFolder subfolder &"\Sharepoint"
Next

Open in new window

0
k1ndredxCommented:
If you need to use the username variable you can use the ExpandEnvironmentStrings to access the username variable and use that in your folder path:


Dim objFso, ofolder

Set oShell = CreateObject( "WScript.Shell" )
user=oShell.ExpandEnvironmentStrings("%UserName%")
Set objFso = CreateObject("Scripting.FileSystemObject")
Set ofolder = objFso.CreateFolder("C:\Users\" & user & "\Sharepoint")

Open in new window

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

merowingerCommented:
%USERPROFILE% delivers the full path directly ;)
0
Moey_GAuthor Commented:
sorry for the late reply all . I have tried all the recommendations except for running the vb script on the server.

I am still unable to see the folder once I run the logon script on a test machine. Any ideas what will be the cause?
0
Moey_GAuthor Commented:
Corrected the script which now creates the folder. Ideally , the folder needs to be created in the Documents folder which is re-directed to the File server. The script is creating a folder in the
%useprofile% folder. This is not re-directed to the server. The Documents folder is re-directed user Group Policy (\\fileserver\users$\%username%\Documents ).

Any other ideas ?

Sorry merowinger , your script will need to be run everyday to make sure all users have the folder. I would prefer this to be part of the logon script.
0
merowingerCommented:
this should then do it
Set objShell = CreateObject( "WScript.Shell" ) 
strUserProfile = objShell.ExpandEnvironmentStrings("%USERPROFILE%") 
Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set ofolder = objFSO.CreateFolder(strUserProfile &"\Documents\Sharepoint")

Open in new window

0
Moey_GAuthor Commented:
Hi merowinger,

Thank you for your help thus far. I am still not having the folder created to the right directory. When you enable Group policy for folder redirection , it creates another path pointing to the server on the network via the properties of documents on a windows 7 machine.

The above works great if you are trying to create a directory locally on the machine ie ( C:\users\%username%\Documents ).

I need the vb script to create a folder on the network (\\fileserver\users$\%username%\Documents ).

Apologies if I have not explained this clearly.
0
merowingerCommented:
ok then try this one!
Set objShell = CreateObject("WScript.Shell") 

strUser = objShell.ExpandEnvironmentStrings("%USERNAME%")  
strFileServer = "Youservername"

Set objFSO = CreateObject("Scripting.FileSystemObject")  
Set ofolder = objFSO.CreateFolder("\\" &strFileServer &"\Users$\" &strUser &"\Documents\Sharepoint")

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Moey_GAuthor Commented:
Works a treat !!! Thanks for all your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.