Batch Extract path and filename from a variable

前端 未结 5 1566
故里飘歌
故里飘歌 2020-11-27 11:18

How can I extract path and filename from a variable?

Setlocal EnableDelayedExpansion
set file=C:\\Users\\l72rugschiri\\Desktop\\fs.cfg

I wa

5条回答
  •  眼角桃花
    2020-11-27 12:17

    @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.

提交回复
热议问题