Computer Hope
Microsoft => Microsoft DOS => Topic started 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?
-
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?
-
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".
-
You could adapt this code:
echo. %cd:~10,0%
-
What's that meant to do?
Why the period after the echo?
-
type that in command prompt and press enter.
I have a habit of putting periods after 'echo'. Still works the same as 'echo '
-
C:\>echo %cd:~20,0%
ECHO is on.
ie %cd~20,0% expands to... nothing.
-
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.
-
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.....
-
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
-
echo. prints a blank line to the screen.
Yes I did know that. ::)
-
so, dudeoxide, what's with this echo %cd:~20,0% thing? What does it do?
-
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...
-
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?)
-
echo. prints a blank line to the screen.
Yes I did know that. ::)
and yet you asked anyway? .... odd.
-
he can use that to cd to his previous location.
-
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?"
-
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......
-
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!
-
well then you change 20 to a number that suits you.
-
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.
-
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
pushd \Foo
Then to get back to the previous directory do
popd
Or if you wanted to go to C:\Documents and Settings you could use the command
pushd "C:\Documents and Settings"
Then to get back to the previous directory do
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:
@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.