Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhtml/bc4ccc5c9b2425712bf75347b4cd2c7f to your computer and use it in GitHub Desktop.
Save dhtml/bc4ccc5c9b2425712bf75347b4cd2c7f 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%
@dhtml
Copy link
Author

dhtml commented Mar 26, 2023

Excellent job, this helped me out just now.

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