Script - Abbrev Folder Path for My Documents

Posted on 2009-02-23
Medium Priority
Last Modified: 2012-05-06
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?
Question by:humbleamateur
  • 3
  • 2
LVL 16

Expert Comment

ID: 23714894
How's about "%userprofile%\My Documents" ?

Expert Comment

ID: 23715226
%username%\my documents
LVL 16

Expert Comment

ID: 23716153
%username%  only gets you (eg)  "cantoris" whereas %userprofile% gets you "c:\documents and settings\cantoris"
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 23718038
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

LVL 16

Accepted Solution

cantoris earned 500 total points
ID: 23719842
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" )

Author Closing Comment

ID: 31550245
It worked perfectly!  Thanks!

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My purpose is to describe the basic concepts of virtual memory as implemented in a modern Windows-based operating system. I will also describe the problems inherent in older systems and how virtual memory solves them. The dark ages - before virtu…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question