split path and take last folder name in batch script
@echo offset MYDIR=C:\FOLDER1\FOLDER2\FOLDER3\set MYDIR1=%MYDIR:~0,-1%for %%f in (%MYDIR1%) do set myfolder=%%~nxfecho %myfolder%
outputs
FOLDER3
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
When your current folder contains spaces then try this:
@echo offfor %%f in ("%CD%") do set LastPartOfFolder=%%~nxfecho %LastPartOfFolder%