Take the 2-minute tour ×

I have been working on building a packaging utility which basically gets all added/modified files between two SVN revisions, then copies them locally and zips them.So far, I have been able to successfully extract all changed files between two revisions.

To go further, I am using xcopy to recursively create folders at a certain directory.

Assuming that the following files have changed when I check two revisions using svn diff command

/temp1/temp2/ (folder created)
/temp1/temp2/temp3 (folder created)

For XCopy to work, I am doing

xcopy local/svn/copy/path d:/{folderpath} 

where folderpath needs to be extracted from the above changed list e.g.

xcopy "C:/LocalSVN/temp1/temp2/temp3/temfile.txt" "d:/temp1/temp2/temp3/"

I need to in my batch file, extract only the folder path and remove the file name.What is the best way to do it in a batch file?

Is there a different way to achieve what I am trying to do?

share|improve this question
You should read the post 5 hours before yours: How to get a Part of the Directory path in a batch file –  jeb Oct 4 '11 at 20:42
I am afraid, this does not solve my problem! The solution works with directories and relates to the path in which the bat file resides.If you read my problem carefully, It has to do with processing strings, which contain a directory path. –  Rupin Oct 5 '11 at 4:40
Perhaps you can find my answer to a [similar post here][1]. [1]: stackoverflow.com/questions/7527529/… –  Arun Oct 6 '11 at 16:53
add comment

2 Answers

up vote 2 down vote accepted

It's nearly the same as in How to get a Part of the Directory path in a batch file

The key is to use the %~dp functionality, and as this only works with parameters (not variables), you can use a FOR-Loop or a subroutine to move your variable into a parameter.

@echo off
set "testString=/temp1/temp2/temp3/temfile.txt"

call :GetPath returnVal "%testString%"
echo %returnVal%
exit /b

set "%1=%~dp2"
exit /b
share|improve this answer
This does'nt work as well..The output is C:\temp1\temp2\temp3\temfile.txt , where as the output I am looking for is just \temp1\temp2\temp3, without the drive letter... –  Rupin Oct 5 '11 at 15:02
As in for /? is explained, d=drive p=path, so you can use set "%1=%~p2" in your case –  jeb Oct 7 '11 at 12:28
This doesn't work if the call is within a FOR loop. How can I solve this scenario? –  Scott Chu Feb 26 at 20:53
@ScottChu I can't see any problem, but you should open a new question with your code –  jeb Feb 26 at 22:47
add comment
@echo off
call :parentfolder %SUBDIR:~0,-1% 
goto :eof

echo %~dp1
goto :eof
share|improve this answer
add comment

Your Answer


