On Thu, 17 Mar 2005 13:45:47 -0500, "TJT" <(E-Mail Removed)> wrote:
>I have a bat file in which I need to know the last node of a directory
>string. I know that I am not properly describing it so let me give an
>example...
>
>Assuming that I am executing a bat file from the directory path
> C:\TestPrograms\Version6\Release2
>
>I would like to be able to obtain the last node ("Release2"). I've tried
>everything but can't seem to get this to work.
>
>I tried something like the following
>SET FullPath=%CD%
>cd..
>SET PartPath=%CD%
>
>At this point
> FullPath=C:\TestPrograms\Version6\Release2
>and
> PartPath=C:\TestPrograms\Version6
>
>I tried executing the following to essentially change
>"C:\TestPrograms\Version6" to empty string but it didn't work as I had hoped
>SET LastNode = %FullPath:%PartPath=%
>
>Any help would be greatly appreciated.
>
>
@echo off
setlocal
call :lastnode "C:\TestPrograms\Version6\Release2"
@echo Last node is %lstn%
@echo Parent path is %prnt%
endlocal
goto :EOF
:lastnode
set lstn=%~n1
set prnt=%~dp1
Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com