Loop over folder string and parse out last folder name

后端 未结 13 1401
-上瘾入骨i
-上瘾入骨i 2020-12-03 05:39

I need to grab the folder name of a currently executing batch file. I have been trying to loop over the current directory using the following syntax (which is wrong at prese

13条回答
  •  有刺的猬
    2020-12-03 06:05

    I found this old thread when I was looking to find the last segment of the current directory. The previous writers answers lead me to the following:

    FOR /D %%I IN ("%CD%") DO SET _LAST_SEGMENT_=%%~nxI
    ECHO Last segment = "%_LAST_SEGMENT_%"
    

    As previous have explained, don't forget to put quotes around any paths create with %_LAST_SEGMENT_% (just as I did with %CD% in my example).

    Hope this helps someone...

提交回复
热议问题