Finding the directory name

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
leftybeaver128
Posts: 11
Joined: 24 May 2011 13:20

Finding the directory name

#1 Post by leftybeaver128 » 08 Nov 2011 17:07

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

alleypuppy
Posts: 82
Joined: 24 Apr 2011 19:20

Re: Finding the directory name

#2 Post by alleypuppy » 08 Nov 2011 22:22

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

leftybeaver128
Posts: 11
Joined: 24 May 2011 13:20

Re: Finding the directory name

#3 Post by leftybeaver128 » 09 Nov 2011 07:34

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!

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Finding the directory name

#4 Post by Ed Dyreen » 09 Nov 2011 08:26

'
~DPO: it doesn't work from the console, only if executed from script.

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

Post Reply