• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 747
  • Last Modified:

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
0
Moey_G
Asked:
Moey_G
1 Solution
 
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
Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

 
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
 
Moey_GAuthor Commented:
Works a treat !!! Thanks for all your help.
0

Featured Post

Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now