Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch to open a folder within a user's folder(c:\users\usernamehere\my documents)?

Tags:

But I am looking for a code that will allow whatever user that uses my batch file to get to their my documents. The idea is that they would type 3, press enter, and then the program would open up their "My Documents" folder.

Unfortunately every user has a different name, so the following command won't work unless it has a specific name after it.

%SystemRoot%\explorer.exe c:\users\James\My Documents 

Is there some sort of replacement for the "James"? A universal command?

like image 316
The Fluffy Robot Avatar asked Jan 28 '12 23:01

The Fluffy Robot


1 Answers

You can use the %UserProfile% environment variable, which points directly to the personal folder of the logged in user:

%SystemRoot%\explorer.exe %UserProfile%\My Documents 

-If you're using windows 7 just do explorer %UserProfile%\Documents (should work with other Windows but I haven't tried...)

this is because any exe in system root can be used as a command and to my knowledge most versions of windows have a folder called "Documents" not "My Documents" it just appears that way to the user (same for Music etc.)

like image 62
Oldskool Avatar answered Oct 20 '22 22:10

Oldskool