DosTips.com

A Forum all about DOS Batch
It is currently 27 Jul 2016 17:00

All times are UTC-06:00




Post new topic  Reply to topic  [ 12 posts ] 
Author Message
PostPosted: 02 Jan 2013 01:08 
Offline

Joined: 29 Dec 2012 23:58
Posts: 9
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 ?


Top
   
PostPosted: 02 Jan 2013 01:20 
Offline

Joined: 08 Jun 2012 07:48
Posts: 65
That code's unnecessary. You could just execute "cd..". That would make the program enter its parent directory


Top
   
PostPosted: 02 Jan 2013 01:24 
Offline

Joined: 29 Dec 2012 23:58
Posts: 9
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.


Top
   
PostPosted: 02 Jan 2013 02:37 
Offline

Joined: 26 Oct 2011 22:38
Posts: 1007
Location: Egypt
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.


Top
   
PostPosted: 02 Jan 2013 02:48 
Offline
Expert

Joined: 10 Feb 2012 02:20
Posts: 5813
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


Top
   
PostPosted: 02 Jan 2013 06:45 
Offline
Expert

Joined: 23 Dec 2011 13:59
Posts: 3147
CD ..

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


Top
   
PostPosted: 03 Jan 2013 05:49 
Offline
Expert

Joined: 17 Oct 2009 08:30
Posts: 378
Location: Russia
"Determine parent folder name without entire folder path" viewtopic.php?f=3&t=2427


Top
   
PostPosted: 04 Jan 2013 06:23 
Offline

Joined: 03 Jan 2013 04:26
Posts: 7
you can use the command CD..

example:


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


Top
   
PostPosted: 04 Jan 2013 22:47 
Offline

Joined: 29 Dec 2012 23:58
Posts: 9
thanks a lot. working on all the possibilities posted.


Top
   
PostPosted: 15 Jan 2013 23:20 
Offline

Joined: 02 Oct 2012 17:21
Posts: 88
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 '\'


Top
   
PostPosted: 16 Jan 2013 00:03 
Offline

Joined: 15 Jan 2013 23:53
Posts: 40
Cd \.
Above command is the best to change root directory.


Top
   
PostPosted: 25 Jan 2013 02:47 
Offline

Joined: 21 Jan 2013 07:09
Posts: 5
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...


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 12 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], misol101, Yahoo [Bot] and 2 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® Forum Software © phpBB Limited