Page 1 of 1

How to jump to the root directory from current directory

Posted: 02 Jan 2013 01:08
by radiantracy
Hi,

My requirement is that if I am in C:/Test/Folder1/Folder2, the batch command shud jump to C:/Test/Folder1. What is the batch command to do the same. My code is :
SET ARGUMENTS=%1
Set PROJROOTFOLDER=%ARGUMENTS%
popd
ECHO %PROJROOTFOLDER%

here %1 gets arg from user and it shud jump to the previous folder. How shud i modify the code jump to a directory above ?

Re: How to jump to the root directory from current directory

Posted: 02 Jan 2013 01:20
by john924xps
That code's unnecessary. You could just execute "cd..". That would make the program enter its parent directory

Re: How to jump to the root directory from current directory

Posted: 02 Jan 2013 01:24
by radiantracy
Hi john924xps, I tried cd.. but its not moving to the root directory.

SET ARGUMENTS=%1

The %1 is fetched from the console of another application which gives oly the program directory say C:/Workspace/Project.
I want the arg to be replaced with C:/Workspace.

Re: How to jump to the root directory from current directory

Posted: 02 Jan 2013 02:37
by abc0502
You can use the pushd command followed by the location you want,
and the CD command should take the switch /D to change to that directory.
as it might that the location you want to change to is behind the current one like to change from

Code: Select all

C:\Documents and Settings\admin>
to

Code: Select all

C:\
using the /D switch will do.

Re: How to jump to the root directory from current directory

Posted: 02 Jan 2013 02:48
by foxidrive
This will set the variable to one directory less.

Code: Select all

@echo off
SET ARGUMENTS=%1
for %%a in ("%~dp1") do set "PROJROOTFOLDER=%%a"
ECHO "%PROJROOTFOLDER%"
pause

Re: How to jump to the root directory from current directory

Posted: 02 Jan 2013 06:45
by Squashman
CD ..

And what you are referring to is not the ROOT. Root would be the drive letter.

Re: How to jump to the root directory from current directory

Posted: 03 Jan 2013 05:49
by !k
"Determine parent folder name without entire folder path" viewtopic.php?f=3&t=2427

Re: How to jump to the root directory from current directory

Posted: 04 Jan 2013 06:23
by skat3444
you can use the command CD..

example:


------------------------------
cd %username%\Downloads
start "downloaded file"
-----------------------------

Re: How to jump to the root directory from current directory

Posted: 04 Jan 2013 22:47
by radiantracy
thanks a lot. working on all the possibilities posted.

Re: How to jump to the root directory from current directory

Posted: 15 Jan 2013 23:20
by carlsomo

Code: Select all

set fullpath=c:\windows\system32
d:
echo %cd%
echo %fullpath%
cd /d %fullpath%\.\..
echo %__CD__% is the parent dir of fullpath with a trailing '\'
echo %cd% is the parent dir of fullpath without the trailing '\'

Re: How to jump to the root directory from current directory

Posted: 16 Jan 2013 00:03
by shirulkar
Cd \.
Above command is the best to change root directory.

Re: How to jump to the root directory from current directory

Posted: 25 Jan 2013 02:47
by suresh_knv
cd .. is the best command to use to get to the just above parent folder and cd \ is used to get to the drive letter as mentioned above...