Skip to content

Instantly share code, notes, and snippets.

@C0nw0nk
Last active January 29, 2023 17:05
Show Gist options
  • Save C0nw0nk/0e48772d1f508dac1eb1de0d0df77559 to your computer and use it in GitHub Desktop.
Save C0nw0nk/0e48772d1f508dac1eb1de0d0df77559 to your computer and use it in GitHub Desktop.
remove last directory folder from variable batch file command line
@echo off & setLocal EnableDelayedExpansion
set root_path="%~dp0"
set "remove_last_folder=%root_path:"=%"
::remove last back slash
set "remove_last_folder=%remove_last_folder:~0,-1%"
::last folder into var
set "last1=%remove_last_folder:\=" & set "lastfolder1=%"
::remove last folder from var
echo its "!remove_last_folder:%lastfolder1%=!"
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment