VB script to create folder to a user profile

Hello,

I have this simple VB script to create a folder to user's profile which works to some extent. The problem I am running into is the profiles in the home directory have a (.cloud) extension (example= jondoe.cloud) The VB script below just recognizes the user name, but not the .cloud. Any ideas anyone??

Dim objFSO, strFolder
strFolder = "\\XXX.local\Site\Home$\%USERNAME%\WINDOWS\Fonts"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(strFolder) Then
   objFSO.CreateFolder(strFolder)
End If

Thanks,

JV
juniorval01Asked:
Who is Participating?
 
Bill PrewCommented:
That's typically due to one of the higher level folders not already existing.  VB isn't like the DOS "mkdir" command, which will automatically create all higher level folders.  In VB you have to make sure each parent exists before creating children.

Typically there are two approaches to solving this.  One is to just shell out to a DOS command and use the MKDIR command for the folder creation.  The other is to use a function that walks down the folders in the path you want to ultimately create and adds any missings ones using VB commands.

I know Rob is up on all of this and can guide you in the code needed, so I won't interfere unless he can't get to this and then I'll lend a hand.  Here's some example code if you want to tackle it on your own.

http://stackoverflow.com/questions/4407386/help-to-create-folder1-folder2-in-windows-using-vbscript-both-the-folders-not

~bp
0
 
santoshmotwaniCommented:
have you tried using "%UserProfile% variable instead on Username?
0
 
Bill PrewCommented:
Can't you just add it in to the path, like:

strFolder = "\\XXX.local\Site\Home$\%USERNAME%.cloud\WINDOWS\Fonts"

~bp
0
WEBINAR: 10 Easy Ways to Lose a Password

Join us on June 27th at 8 am PDT to learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees. We'll cover the importance of multi-factor authentication and how these solutions can better protect your business!

 
RobSampsonCommented:
Or the .cloud might be the domain:
strFolder = "\\XXX.local\Site\Home$\%USERNAME%.%USERDOMAIN%\WINDOWS\Fonts"

Rob.
0
 
juniorval01Author Commented:
Thanks guys for the responses back.

@Rob, I have added the .%USERDOMAIN% and I was able to navigate to the location which is great. But it wont create the folder "FONTS".

Line: 5
Char: 4
Error: Path not found
Code: 800A004C

Any ideas?
0
 
juniorval01Author Commented:
@BP,

I went ahead and went with the info you sent me and worked as you expected.

Many thanks to BP and Rob!
0
 
Bill PrewCommented:
Welcome, glad that helped.

~bp
0
 
RobSampsonCommented:
Thanks Bill for the support.  Thanks JV for the assist points.  Glad to help.

Rob.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.