我目前正在尝试使用批处理来获取特定的文件名,然后将其放入一个变量中,因为文件名可能会改变,但"client“或"mui”部分不会改变。
这两行是我首先尝试的。使用dir搜索路径,使用/b只获取名称,然后使用"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)发布于 2018-09-05 03:57:05
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"在这里。
https://stackoverflow.com/questions/52172476
复制相似问题