View unanswered posts | View active topics It is currently 29 Jul 2014 20:56



Post new topic Reply to topic  [ 12 posts ] 
How to jump to the root directory from current directory 
Author Message

Joined: 29 Dec 2012 23:58
Posts: 9
Post How to jump to the root directory from current directory
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 ?


02 Jan 2013 01:08
Profile

Joined: 08 Jun 2012 07:48
Posts: 65
Post Re: How to jump to the root directory from current directory
That code's unnecessary. You could just execute "cd..". That would make the program enter its parent directory


02 Jan 2013 01:20
Profile

Joined: 29 Dec 2012 23:58
Posts: 9
Post Re: How to jump to the root directory from current directory
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.


02 Jan 2013 01:24
Profile

Joined: 26 Oct 2011 22:38
Posts: 1007
Location: Egypt
Post Re: How to jump to the root directory from current directory
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:
C:\Documents and Settings\admin>
to
Code:
C:\
using the /D switch will do.


02 Jan 2013 02:37
Profile

Joined: 10 Feb 2012 02:20
Posts: 4025
Post Re: How to jump to the root directory from current directory
This will set the variable to one directory less.

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


02 Jan 2013 02:48
Profile

Joined: 23 Dec 2011 13:59
Posts: 1758
Post Re: How to jump to the root directory from current directory
CD ..

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


02 Jan 2013 06:45
Profile
Expert

Joined: 17 Oct 2009 08:30
Posts: 378
Location: Russia
Post Re: How to jump to the root directory from current directory
"Determine parent folder name without entire folder path" viewtopic.php?f=3&t=2427


03 Jan 2013 05:49
Profile

Joined: 03 Jan 2013 04:26
Posts: 7
Post Re: How to jump to the root directory from current directory
you can use the command CD..

example:


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


04 Jan 2013 06:23
Profile

Joined: 29 Dec 2012 23:58
Posts: 9
Post Re: How to jump to the root directory from current directory
thanks a lot. working on all the possibilities posted.


04 Jan 2013 22:47
Profile

Joined: 02 Oct 2012 17:21
Posts: 83
Post Re: How to jump to the root directory from current directory
Code:
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 '\'


15 Jan 2013 23:20
Profile

Joined: 15 Jan 2013 23:53
Posts: 40
Post Re: How to jump to the root directory from current directory
Cd \.
Above command is the best to change root directory.


16 Jan 2013 00:03
Profile

Joined: 21 Jan 2013 07:09
Posts: 5
Post Re: How to jump to the root directory from current directory
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...


25 Jan 2013 02:47
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 


Who is online

Users browsing this forum: ShadowThief and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Forum style by Vjacheslav Trushkin for Free Forums/DivisionCore.