Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Change to current user's directory in a batch file

How is it possible to change to a user default directory

Is there a default variable that can be used e.g. %USER%

would return: C:\Users\MyUsername

like image 524
Michael Skelton Avatar asked Aug 23 '11 10:08

Michael Skelton


People also ask

What is the current directory in a batch file?

It is the directory from where you start the batch file. E.g. if your batch is in c:\dir1\dir2 and you do cd c:\dir3 , then run the batch, the current directory will be c:\dir3 .

What does %% A mean in batch file?

%%a refers to the name of the variable your for loop will write to. Quoted from for /? : FOR %variable IN (set) DO command [command-parameters] %variable Specifies a single letter replaceable parameter. (set) Specifies a set of one or more files. Wildcards may be used.

How do I find my home directory in CMD?

To navigate to your home directory, use "cd" or "cd ~" To navigate up one directory level, use "cd .." To navigate to the previous directory (or back), use "cd -"


1 Answers

Use %HOMEPATH%.

So:

CD %HOMEPATH% 
like image 133
Oded Avatar answered Oct 12 '22 13:10

Oded