Batch Extract path and filename from a variable

batch-file, path

Solution

@ECHO OFF
SETLOCAL
set file=C:\Users\l72rugschiri\Desktop\fs.cfg
FOR %%i IN ("%file%") DO (
ECHO filedrive=%%~di
ECHO filepath=%%~pi
ECHO filename=%%~ni
ECHO fileextension=%%~xi
)

Not really sure what you mean by no "function"

Obviously, change `ECHO` to `SET` to set the variables rather thon ECHOing them...

See `for` documentation for a full list.

ceztko's test case (for reference)

@ECHO OFF
SETLOCAL
set file="C:\Users\ l72rugschiri\Desktop\fs.cfg"
FOR /F "delims=" %%i IN ("%file%") DO (
ECHO filedrive=%%~di
ECHO filepath=%%~pi
ECHO filename=%%~ni
ECHO fileextension=%%~xi
)

Comment : please see comments.

Problem

How can I extract path and filename from a variable? ``` Setlocal EnableDelayedExpansion set file=C:\Users\l72rugschiri\Desktop\fs.cfg ``` I want to do that without using any function or any GOTO. is it possible?

Original source

Related problems