split path and take last folder name in batch script

后端 未结 4 1466
梦谈多话
梦谈多话 2020-12-05 14:18

I want to split the string (having a path) with \\and take last folder name in a variable. Please help.

e.g
mypath=D:\\FOLDER1\\FOLDER2\\FOLDER3\\

4条回答
  •  渐次进展
    2020-12-05 14:44

    When your current folder contains spaces then try this:

    @echo off
    for %%f in ("%CD%") do set LastPartOfFolder=%%~nxf
    
    echo %LastPartOfFolder%
    

提交回复
热议问题