DOS BAT file equivalent to Unix basename command?

前端 未结 8 1357
野趣味
野趣味 2020-12-03 00:43

Is there an easy way to get to the basename (file name without extension) of a DOS file name using the DOS BAT command language?

I agree: format c:\\ is

8条回答
  •  长情又很酷
    2020-12-03 01:22

    For command-line

    for /F %i in ("c:\foo\bar.txt") do @echo %~ni
    

    For .bat Files

    for /F %%i in ("c:\foo\bar.txt") do @echo %%~ni
    

    output: bar

    p.s. if path contains space, use @ciantic's version.

    (Further Reading: http://www.computerhope.com/forhlp.htm )

提交回复
热议问题