Page 1 of 1

Finding the directory name

Posted: 08 Nov 2011 17:07
by leftybeaver128
Hey guys,
Can anyone tell me in Windows 7/Vista, how to find the name of the current user and where a certain file is located?

For example:
I need to know what the person's username is so I can find the C:\Users\(Name)

Also, I need to know where the file that is executing (as in my batch file) where it is on the computer.

Thanks in advance guys!

--Matt

Re: Finding the directory name

Posted: 08 Nov 2011 22:22
by alleypuppy
To find the user

Code: Select all

@ECHO OFF
ECHO %USERNAME%
ECHO %USERPROFILE%
PAUSE

To find the location of the batch file

Code: Select all

@ECHO OFF
ECHO %~DP0
PAUSE

Re: Finding the directory name

Posted: 09 Nov 2011 07:34
by leftybeaver128
alleypuppy wrote:To find the user

Code: Select all

@ECHO OFF
ECHO %USERNAME%
ECHO %USERPROFILE%
PAUSE

To find the location of the batch file

Code: Select all

@ECHO OFF
ECHO %~DP0
PAUSE



Okay so I get the first one. That make sense. But when I try the second one, it doesn't work.

I type in "echo %~DPO" but it just returns with %~DPO.

Any help?

And thanks for the initial help!

Re: Finding the directory name

Posted: 09 Nov 2011 08:26
by Ed Dyreen
'
~DPO: it doesn't work from the console, only if executed from script.

enter for /? for help on %0, %*, %~dp0...