Batch Extract path and filename from a variable

前端 未结 5 1577
故里飘歌
故里飘歌 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 11:54

    All of this works for me:

    @Echo Off
    Echo Directory = %~dp0
    Echo Object Name With Quotations=%0
    Echo Object Name Without Quotes=%~0
    Echo Bat File Drive = %~d0
    Echo Full File Name = %~n0%~x0
    Echo File Name Without Extension = %~n0
    Echo File Extension = %~x0
    Pause>Nul
    

    Output:

    Directory = D:\Users\Thejordster135\Desktop\Code\BAT\
    
    Object Name With Quotations="D:\Users\Thejordster135\Desktop\Code\BAT\Path_V2.bat"
    
    Object Name Without Quotes=D:\Users\Thejordster135\Desktop\Code\BAT\Path_V2.bat
    
    Bat File Drive = D:
    
    Full File Name = Path.bat
    
    File Name Without Extension = Path
    
    File Extension = .bat
    

提交回复
热议问题