Script - Abbrev Folder Path for My Documents

I'm trying write a script that will copy files into users' My Documents folders, but the only path I know to get to My Documents requires the user name: C:\Documents and Settings\orenb000\My Documents\.  Is there a path I can use that could get me to My Documents without knowing the user name?
humbleamateurAsked:
Who is Participating?
 
cantorisCommented:
You can't use environment variables directly in VBScript like that - you can in a batch file though.

You will need to use the WScript Shell object to expand them into their actual strings:

Set objShell = CreateObject( "WScript.Shell" )
strProfilePath=objShell.ExpandEnvironmentStrings("%UserProfile%")
0
 
cantorisCommented:
How's about "%userprofile%\My Documents" ?
0
 
ksmith247Commented:
%username%\my documents
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
cantorisCommented:
%username%  only gets you (eg)  "cantoris" whereas %userprofile% gets you "c:\documents and settings\cantoris"
0
 
humbleamateurAuthor Commented:
Hmmm....I don't know what I'm doing wrong.  I tried both of these out in the attached code and got "Path Not Found" errors both times.  Is there something wrong with my code?  Thanks for all your help!

Dim fs As Object
    
Set fs = CreateObject("Scripting.FileSystemObject")
 
fs.CopyFile "C:\test.txt", "%userprofile%\My Documents\test.txt"
    
fs.CopyFile "C:\test.txt", "C:\Documents and Settings\%username%\My Documents\test.txt"

Open in new window

0
 
humbleamateurAuthor Commented:
It worked perfectly!  Thanks!
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.