How to jump to the root directory from current directory
Moderator: DosItHelp
-
- Posts: 9
- Joined: 29 Dec 2012 23:58
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 ?
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 ?
-
- Posts: 65
- Joined: 08 Jun 2012 07:48
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
-
- Posts: 9
- Joined: 29 Dec 2012 23:58
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.
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
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
to using the /D switch will do.
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>
Code: Select all
C:\
Re: How to jump to the root directory from current directory
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
CD ..
And what you are referring to is not the ROOT. Root would be the drive letter.
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
"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
you can use the command CD..
example:
------------------------------
cd %username%\Downloads
start "downloaded file"
-----------------------------
example:
------------------------------
cd %username%\Downloads
start "downloaded file"
-----------------------------
-
- Posts: 9
- Joined: 29 Dec 2012 23:58
Re: How to jump to the root directory from current directory
thanks a lot. working on all the possibilities posted.
Re: How to jump to the root directory from current directory
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
Cd \.
Above command is the best to change root directory.
Above command is the best to change root directory.
-
- Posts: 5
- Joined: 21 Jan 2013 07:09
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...