代码之家  ›  专栏  ›  技术社区  ›  jsc

批量输出文件名到变量

  •  0
  • jsc  · 技术社区  · 6 年前

    我目前正在尝试使用批处理来获取一个特定的文件名,然后将其放入一个变量中,因为文件名可能会更改,但“client”或“mui”部分不会更改。

    dir "\\server\path\here" /b | Find "client" | set Client
    dir "\server\path\here" /b | Find "mui" | set MUI
    

    所以,我试着用我的手在这些其他项目,我发现在一些谷歌,但这些也没有工作。

    FOR "tokens=*" %%a in ('DIR "\\server\path\here\"' /b) do (SET OUTPUT=%%a)
    for /f "tokens=*" %%i in ('dir \\\server\path\here /b | Find client') do @echo %%i
    for /f %%a in ('dir \\server\path\here /B | find "client"') do set FileCount=%%a
    

    我错过了什么或者做错了什么?

    对于那些后来来这里的人

    for /f "tokens=*" %%i in ('dir \\server\path\here /b ^| Find "client"') do (Set BaseClient=%%i)
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Stephan    6 年前
    FOR "tokens=*" %%a in ('DIR "\\server\path\here\"' /b) do (SET OUTPUT=%%a)
    

    应该有效(如果您查找唯一或最后一个文件)

    for /f "tokens=*" %%i in ('dir \\server\path\here /b ^| Find "client"') do @echo %%i
    

    find 字符串(可能) dir /b /a-d ... find /i "client" 可能是个好主意),而且 |

    for /f %%a in ('dir \\server\path\here /B ^| find "client"') do set FileCount=%%a
    

    文件计数?你可能想要 dir /b /a-d ... ^| find /i /c "client" 在这里。