Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to create directory basesd on expandenvironment string

Status
Not open for further replies.

chouck

MIS
Jan 30, 2005
32
US
ok, so i would like to create a folder on a pc under the logged on user's profile.

i can echo the expand environment string and get the user profile path, but do not know how to pipe it into the createfolder usage.

Any help is greatly appreciated

here is sample script:

dim ofso, oshell, onet, ouser, ofolder, behruserprof

set ofso = createobject("scripting.filesystemobject")
set oshell = createobject("wscript.shell")
set onet = createobject("wscript.network")
ouser = onet.username


wscript.echo ouser

WScript.Echo("Userprofile is " + oshell.ExpandEnvironmentStrings("%USERProfile%"))

set ofolder = ofso.createfolder("%userprofile%\locals~1\applic~1\somedir\somesubdir\someothersubdir")
 
you mean like this?

Code:
UserProfilePath = oshell.ExpandEnvironmentStrings("%USERProfile%")
set ofolder = ofso.createfolder(UserProfilePath & "\locals~1\applic~1\somedir\somesubdir\someothersubdir")


--------------------------------------
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs,
and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning.
 
Thanks for the help. It worked perfectly. But let me pick your brain a little bit more.

If I wanted to copy a file from one location to the new %userprofilepath%, how would I do the syntax:

ofso.copyfile "z:\networkshare\share\notes.ini "userprofilepath%\somedir\somesubdir\anothersubdir

Thanks for the help already and thanks again in advance
 
ofso.copyfile "z:\networkshare\share\notes.ini" userprofilepath & "\somedir\somesubdir\anothersubdir\"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
On the above example,
What if I want to make a copy of the file to the "My Documents" folder for several different users on Win XP. How do I retrieve their windows username?
Example:

dim fso,fldr
set fso=CreateObject("Scripting.FileSystemObject")
if (fso.FolderExists("C:\Document and Settings\username\My Documents\TEST")) then
Msgbox("Folder Exists")
else
Msgbox("need to create folder")
fso.CreateFolder("C:\Document and Settings\username\My Documents\TEST")
end if
 
You may browse the SubFolders collection of a "C:\Document and Settings" Folder object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I am pretty new at scripting so I am not sure I understand...

I need to copy a file from a share network directory to the My Documents folder on several users. I need to send them the script for them to run on their pc. If the "Test" folder doesn't exist under "My Documents" I want to create it. It works fine when I use their login id i.e. "C:\Document and Settings\doej\My Documents\TEST"

I however don't want to send a different script to each user. How do I retrieve their Id?

Thanks,
 
Set Sh = CreateObject("WScript.Shell")
strTest = Sh.SpecialFolders("MyDocuments") & "\TEST"


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top