Get filename from string-path?

前端 未结 3 1577
独厮守ぢ
独厮守ぢ 2020-12-29 02:37

How do I get the filename from this string?

\"C:\\Documents and Settings\\Usuario\\Escritorio\\hello\\test.txt\"

output:

\"         


        
相关标签:
3条回答
  • 2020-12-29 02:48

    if your path comes as a parameter, just use:

    %~nx1 (1 is for the first param and we suppose it's the first one)

    echo %~nx1 would return directly test.txt

    0 讨论(0)
  • 2020-12-29 03:02

    Method 1

    for %%F in ("C:\Documents and Settings\Usuario\Escritorio\hello\test.txt") do echo %%~nxF
    

    Type HELP FOR for more info.

    Method 2

    call :sub "C:\Documents and Settings\Usuario\Escritorio\hello\test.txt"
    exit /b
    
    :sub
    echo %~nx1
    exit /b
    

    Type HELP CALL for more info.

    0 讨论(0)
  • 2020-12-29 03:14

    Assuming you need the the names of files under the "c:\temp" directory tree (including sub-directories):

    FOR /R c:\temp %i in (*.*) do echo %~nxi
    
    0 讨论(0)
提交回复
热议问题