views:

825

answers:

7

Is there a command line that I can get the full path to current directory?(in DOS)

+6  A: 

"chdir" with no arguments.

Trevor Bramble
*How did* you understand what he was trying to say from *that* ? And, under dos and windows cmd, its usually just "cd"
ldigas
Honestly, I couldn't think of anything else they might be trying to ask as the question stated.
Trevor Bramble
@Trevor - Hehehe, yes. True.
ldigas
Can I store this path inside a variable in a .bat file?
@unknown - you might be better off by describing the original problem in the first place.
ldigas
+3  A: 

On Unix?

pwd

scurial
A: 

Got it . Looks like chdir works Thanks

This is not an answer. Use a comment or edit your question.
Geoffrey Chetwood
Glad that worked. Is it not possible for you to mark my answer as the solution?
Trevor Bramble
+1  A: 

For Windows, cd by itself will show you the current working directory.

For UNIX and workalike systems, pwd will perform the same task. You can also use the $PWD shell variable under some shells. I am not sure if Windows supports getting the current working directory via a shell variable or not.

Michael Trausch
I can't however understand why he needs "cd" to see his current dir. By default, it is visible as day. And if he's changed it, than he certainly knows what "cd" does.
ldigas
He needs it in a batch file.
Ikke
A: 

I'm sorry. I guess my qurstion was really unclear. I am trying to save the corrent path inside a variable in a .bat file. I thought I can just do SET var = cd. But I guess it doesnt work.

This is not an answer. Use a comment or edit your question.
Geoffrey Chetwood
Edit your question. No need to add an answer if it isn't one.
George Stocker
@unknown - do you want maybe "set MyDir=%cd%" (without quotes) ?
ldigas
+1  A: 

Based on the follow up question (store the data in a variable) in the comments to the chdir post I'm betting he wants to store the current path to restore it after changeing directories.

The original user should look at "pushd", which changes directory and pushes the current one onto a stack that can be restored with a "popd". On any modern Windows cmd shell that is the way to go when making batch files.

If you really need to grab the current path then modern cmd shells also have a %CD% variable that you can easily stuff away in another variable for reference.

Mark
A: 

Quote the Windows help for the set command (set /?):

If Command Extensions are enabled, then there are several dynamic
environment variables that can be expanded but which don't show up in
the list of variables displayed by SET.  These variable values are
computed dynamically each time the value of the variable is expanded.
If the user explicitly defines a variable with one of these names, then
that definition will override the dynamic one described below:

**%CD% - expands to the current directory string.**

%DATE% - expands to current date using same format as DATE command.

%TIME% - expands to current time using same format as TIME command.

%RANDOM% - expands to a random decimal number between 0 and 32767.

%ERRORLEVEL% - expands to the current ERRORLEVEL value

%CMDEXTVERSION% - expands to the current Command Processor Extensions
    version number.

%CMDCMDLINE% - expands to the original command line that invoked the
    Command Processor.
Patrick Cuff