Jump to content

Change Directory In Addition To Changing Folder


Gape

Recommended Posts

I want to change directory in addition to changing folder.

This is possible on the Windows 2000/XP with "/d" parameter.

cd /d %winbootdir%

How can I do same thing on Windows 98?

Thx.

Link to comment
Share on other sites


Gape

This wiil give change drive and directory functions in script.

@echo off
:: create change drive and directory bat
:: before changing drive and directory execute pushd.bat
:: then execute cdd.bat when finished and you wish to return execute popd.bat
echo @echo off > %windir%\cdd.bat
echo %%1\ >> %windir%\cdd.bat
echo cd %%1 >> %windir%\cdd.bat
:: create pushd.bat and popd.bat
echo %%"%% echo e 100 "cdd " >%temp%\script.txt %%"%% > %windir%\pushd.bat
echo %%"%% echo rcx>>%temp%\script.txt %%"%% >> %windir%\pushd.bat
echo %%"%% echo 4>>%temp%\script.txt %%"%% >> %windir%\pushd.bat
echo %%"%% echo n %windir%\popd.bat>>%temp%\script.txt %%"%% >> %windir%\pushd.bat
echo %%"%% echo w >> %temp%\script.txt %%"%% >> %windir%\pushd.bat
echo %%"%% echo q >>%temp%\script.txt %%"%% >> %windir%\pushd.bat
echo %%"%% debug <%temp%\script.txt > NUL %%"%% >> %windir%\pushd.bat
echo %%"%% del %temp%\script.txt %%"%% >> %windir%\pushd.bat
echo %%"%% truename | find ":" >> %windir%\popd.bat %%"%% >> %windir%\pushd.bat

Add the above to begining of script.

Creates cdd.bat and pushd.bat.

Pushd.bat will create popd.bat each time it's called.

call %windir%\pushd.bat
call cdd %windir%
:: do somthing here
:: for example
dir/a/ogen
:: return to original drive and directory
call %windir%\popd.bat

A sample usage above. Each time you need it call pushd.bat first,

then call cdd.bat. Do what you need to do then call popd.bat.

:: when all done clean up
del %windir%\pushd.bat
del %windir%\popd.bat
del %windir%\cdd.bat

At end of script use above.

credits:

cdd.bat

http://home7.inet.tele.dk/batfiles/main/tricktip.htm

pushd.bat(modified to use cdd.bat)

http://www.ericphelps.com/batch/samples/pushpath.bat.txt

Link to comment
Share on other sites

Gape

Yes it's the same as the cdd.bat above.

The rest of the code gives the ability to return to the starting directory

across drive and directory. Thought it might be usefull if the service pack

was launched from a drive other than c:.

The period after %winbootdir% is not needed.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...