Skip to content

Instantly share code, notes, and snippets.

@Ciantic
Created April 1, 2016 15:11
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save Ciantic/092ec71fa76429cebd666bb6c789d089 to your computer and use it in GitHub Desktop.
Save Ciantic/092ec71fa76429cebd666bb6c789d089 to your computer and use it in GitHub Desktop.
How to get filename, dirname, and basename in bat?
set filepath="C:\some path\having spaces.txt"
for /F "delims=" %%i in (%filepath%) do set dirname="%%~dpi"
for /F "delims=" %%i in (%filepath%) do set filename="%%~nxi"
for /F "delims=" %%i in (%filepath%) do set basename="%%~ni"
echo %dirname%
echo %filename%
echo %basename%
@soiqualang
Copy link

Thanks!

@Michael-Soyka
Copy link

Thx

@Hoax017
Copy link

Hoax017 commented Aug 13, 2021

Perfect!

@ktaranek
Copy link

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment