how can I get the last part of a given Path?
c:\dir1\dir2\dir3\
should result in
dir3\
Thank You
Joachim
set p=c:\dir1\dir2\dir3\
if %p:~-1%==\ set p=%p:~0,-1%
for %%G in (%p%) do set p=%%~nxG\
echo %p%
Cheers,
Tomek
@echo off
set p=c:\dir 1\dir 2\dir 3\
for %%G in ("%p%.") do set p=%%~nxG
echo %p%
pause
Nice trick Foxidrive. I've never seen that one before.
Cheers,
Tomek
80} How can I extract the last part of a path such as C:\ABC\DEF\GHI\?
http://www.netikka.net/tsneti/info/tscmd080.htm
144} How do I parse the items from a path like C:\a\b\c\d ?
http://www.netikka.net/tsneti/info/tscmd144.htm
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FI-65101, Finland
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html
>Joachim Hofmann <spei...@freenet.de> wrote:
>> how can I get the last part of a given Path?
>> c:\dir1\dir2\dir3\
>> should result in
>> dir3\
>
> 80} How can I extract the last part of a path such as C:\ABC\DEF\GHI\?
> http://www.netikka.net/tsneti/info/tscmd080.htm
>
> 144} How do I parse the items from a path like C:\a\b\c\d ?
> http://www.netikka.net/tsneti/info/tscmd144.htm
Try this Timo, it seems to handle these cases just fine:
@echo off
call :next "C:\ABC\\DEF XYZ\.GHI\" A
call :next "C:\ABC\\DEF XYZ\.GHI\\" B
call :next "C:\ABC\DEF XYZ\.GHI\" C
call :next "C:\ABC\DEF XYZ\.GHI" D
call :next "C:\ABC\DEF XYZ\GHI\" E
call :next "C:\ABC\DEF XYZ\GHI" F
call :next "d:\folder 1\folder 2\folder 3\" G
call :next "d:\folder 1\folder 2\folder 3.abc\" H
call :next "d:\folder 1\folder 2\folder 3.def" I
goto :eof
:next
set "p=%~1"
for %%G in ("%p%.") do set p=%%~nxG
echo %2 %p%
pause
> Try this Timo, it seems to handle these cases just fine:
Thanks. Added a link in the FAQ to your posting.
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FI-65101, Finland
Useful CMD script tricks http://www.netikka.net/tsneti/info/tscmd.htm