split path and take last folder name in batch script
When your current folder contains spaces then try this:
@echo off
for %%f in ("%CD%") do set LastPartOfFolder=%%~nxf
echo %LastPartOfFolder%
try:
for %f in (C:\FOLDER1\FOLDER2\FOLDER3\.) do set myfolder=%~nxf
works also:
for %f in (C:\FOLDER1\FOLDER2\FOLDER3.) do set myfolder=%~nxf
@echo off
set MYDIR=C:\FOLDER1\FOLDER2\FOLDER3\
set MYDIR1=%MYDIR:~0,-1%
for %%f in (%MYDIR1%) do set myfolder=%%~nxf
echo %myfolder%
outputs
FOLDER3