Computer Hope

Microsoft => Microsoft DOS => Topic started by: reinaker on May 19, 2007, 07:47:28 AM

Title: CD command
Post by: reinaker on May 19, 2007, 07:47:28 AM
I am using the MS version XP, how do I return to a previous directory?
Title: Re: CD command
Post by: Carbon Dudeoxide on May 19, 2007, 08:35:24 AM
Welcome to ComputerHope, Reinaker.

I don't quite understand your queston. By returning to the previous directory, do you mean this:

CD = C:\windows\system32\
and change it to
C:\windows\

Is that what you mean?
Title: Re: CD command
Post by: contrex on May 19, 2007, 09:07:37 AM
CD command syntax:

CD (alone) displays current directory

CD Drive: displays current directory on Drive:

CD directory changes to that directory

CD /D (directory) changes to that directory and changes drive to drive letter D

CD.. change to parent directory

That's it. No change to "previous directory".







Title: Re: CD command
Post by: Carbon Dudeoxide on May 19, 2007, 09:10:40 AM
You could adapt this code:

Code: [Select]
echo. %cd:~10,0%
Title: Re: CD command
Post by: contrex on May 19, 2007, 09:15:52 AM
What's that meant to do?

Why the period after the echo?
Title: Re: CD command
Post by: Carbon Dudeoxide on May 19, 2007, 09:19:48 AM
type that in command prompt and press enter.
I have a habit of putting periods after 'echo'. Still works the same as 'echo '
Title: Re: CD command
Post by: contrex on May 19, 2007, 09:26:17 AM
Code: [Select]
C:\>echo %cd:~20,0%
ECHO is on.

ie %cd~20,0% expands to... nothing.
Title: Re: CD command
Post by: WillyW on May 19, 2007, 09:26:50 AM
What's that meant to do?

Why the period after the echo?


echo.      prints a blank line to the screen.

What it would do in his example, ... I really don't know.  I'd have to try it and see.
Maybe it is just a typo.

Title: Re: CD command
Post by: Carbon Dudeoxide on May 19, 2007, 09:29:28 AM
echo hello
works just the same as
echo.hello
Maybe it just works on XP or something, i dunno.

I just realised reinaker is not a member anymore. Wonder what happened.....
Title: Re: CD command
Post by: WillyW on May 19, 2007, 09:29:49 AM
I am using the MS version XP, how do I return to a previous directory?

By any chance,  is this a repetitive thing?    In that you don't want to have to type out the whole path each time you wish to return to a certain directory, and whatever you are doing necessitates a lot of dir changing?

If so,  there is a way to get around that.

Check out:
http://www.computerhope.com/doskeyhl.htm

Title: Re: CD command
Post by: contrex on May 19, 2007, 09:31:25 AM

echo.      prints a blank line to the screen.


Yes I did know that.  ::)


Title: Re: CD command
Post by: contrex on May 19, 2007, 09:32:45 AM
so, dudeoxide, what's with this echo %cd:~20,0% thing? What does it do?
Title: Re: CD command
Post by: Carbon Dudeoxide on May 19, 2007, 09:34:36 AM
example:
echo %cd%  --> c:\documents and settings\user
echo %cd:~20,0% --> C:\documents and set

does that explain it? Basically gets rid of 20 letters at the end of the command...
Title: Re: CD command
Post by: contrex on May 19, 2007, 09:36:17 AM
Quote
Basically gets rid of 20 letters at the end of the command...

I knew it did that. I do understand about string slicing. I meant what is the purpose of it. As in, what has it got to do with the question the guy asked.

(Sorry, am I being dumb here?)
Title: Re: CD command
Post by: WillyW on May 19, 2007, 09:36:59 AM

echo.      prints a blank line to the screen.


Yes I did know that.  ::)





and yet you asked anyway?        .... odd.

Title: Re: CD command
Post by: Carbon Dudeoxide on May 19, 2007, 09:38:24 AM
he can use that to cd to his previous location.
Title: Re: CD command
Post by: contrex on May 19, 2007, 09:41:14 AM

echo.      prints a blank line to the screen.


Yes I did know that.  ::)





and yet you asked anyway?        .... odd.



Maybe English is not your first language? I meant, "What is the reason why you have put a period after the echo command?", not "What does a period do after an echo command?"

Title: Re: CD command
Post by: Carbon Dudeoxide on May 19, 2007, 09:43:42 AM
Lol, what does it matter.
I find it easier for me to use 'echo. text' than 'echo  text'
You dont have to use the period for %cd:~20,0% but i did coz i could......
Title: Re: CD command
Post by: contrex on May 19, 2007, 09:46:37 AM
he can use that to cd to his previous location.

Oh right. So I'm in D:\My Folders\*censored*\Mom don't look in here\Babes\Redheads and I

type CD d:\

So now I'm in d:\

I type your command and it cuts the last 20 characters off the directory name, which is actually 3 characters long, so I end up with an empty string, which ECHO interprets as a request to show ECHO status, so it says "ECHO is on", and that gets me back to my previous folder? Is that how it works?

That's a real clever DOS tip, dudeoxide! i would nevah have thunk of that all on my lonesome!

Title: Re: CD command
Post by: Carbon Dudeoxide on May 19, 2007, 10:03:05 AM
well then you change 20 to a number that suits you.
Title: Re: CD command
Post by: contrex on May 19, 2007, 10:07:49 AM
It's only useful if "where you were before" is  a parent folder of where you are now. typing cd.. (enter) and then repeatedly recalling it with the up arrow would do the same thing.
Title: Re: CD command
Post by: GuruGary on May 19, 2007, 02:28:51 PM
Reinaker: You can use PUSHD and POPD.

For example, if you start off in
Contrex's directory of
D:\My Folders\*censored*\Mom
And you want to go to the directory D:\Foo, you could use the command
Code: [Select]
pushd \FooThen to get back to the previous directory do
Code: [Select]
popdOr if you wanted to go to C:\Documents and Settings you could use the command
Code: [Select]
pushd "C:\Documents and Settings"Then to get back to the previous directory do
Code: [Select]
popd
Another tip ... if you are writing a batch file that changes directories and it ends up leaving you in a directory used by the batch file instead of the original, you can use the SETLOCAL command.  Example:
Code: [Select]
@echo off
setlocal
cd \Temp
ren *.new *.old
In this example the batch file would leave you in whatever directory you started in.  Without the SETLOCAL command, the batch file would leave you in \Temp.