Page 1 of 1

How to go to this directory???

Posted: 13 Sep 2010 05:44
by Mohammad_Dos
Hi,
for example I want to go to this directory:
D:\my pic\new

I can use this:

D:
cd "my pic"
cd new



I want go to this directory just by one command line. What should I do?

or

for example in dos I have:

%dir%=d:\my pic\new

How to go to the directory in %dir%?

Re: How to go to this directory???

Posted: 13 Sep 2010 07:25
by !k
Read cd/?

Re: How to go to this directory???

Posted: 13 Sep 2010 10:02
by Mohammad_Dos
ok. thank u
my first question answered. but my secont question not answered yet.
please guide me


new question:

for example my batch file in this directory:
d:\new folder

I run the batch file and at last now in batch file we are in this directory:
f:\

How to back to first directory in dos(d:\new folder)?
How to find the directory that runing batch file is in it and how to go to this directory?

Re: How to go to this directory???

Posted: 13 Sep 2010 10:24
by aGerman
There are a lot of possibilities. Try PUSHD and POPD.
Example:

Code: Select all

@echo off &setlocal
echo %cd%
cd /d "D:\my pic\new"
echo %cd%
pushd "F:\"
echo %cd%
popd
echo %cd%
pause


Otherwise the drive and path of your batch file you can find in %~dp0 so you could use

Code: Select all

cd /d "%~dp0"

if you want to change the working directory to the folder your batch file is saved in.

Regards
aGerman

Re: How to go to this directory???

Posted: 13 Sep 2010 10:28
by !k
Mohammad_Dos wrote:How to find the directory that runing batch file is in it and how to go to this directory?

1st way

Code: Select all

set "home=%cd%"
...
...
chdir /d %home%

2nd way

Code: Select all

chdir /d %~dp0

3rd way

Code: Select all

pushd f:\
...
...
popd

Re: How to go to this directory???

Posted: 15 Sep 2010 08:44
by Mohammad_Dos
thank u very much !k and aGerman

Re: How to go to this directory???

Posted: 19 Nov 2010 07:27
by Mohammad_Dos
and now I have a new question.
How to copy some files to directory that the batch file is in it?

for example I runed a batch file and want copy all files in "D:\new Folder\Pic" to batch file directory

Re: How to go to this directory???

Posted: 20 Nov 2010 11:03
by !k
%~dp0

Re: How to go to this directory???

Posted: 20 Nov 2010 12:04
by Mohammad_Dos
thank u very very much