【发布时间】:2016-12-07 16:24:05
【问题描述】:
我正在尝试在所有驱动器中搜索文件名。单独使用dir 命令时一切正常:
C:\>dir /s C:\*blabla*
Volume in drive C has no label.
Volume Serial Number is 2AB1-3FBD
Directory of C:\Users\Administrator\Desktop
02/08/2016 11:21 0 blabla.txt
1 File(s) 0 bytes
Total Files Listed:
1 File(s) 0 bytes
0 Dir(s) 28?369?825?792 bytes free
但是在循环中使用它会失败:
FOR /F "skip=1 delims=" %x in ('wmic logicaldisk get caption') do dir /s %x*blabla*
*blabla* Administrator\Desktop>dir /s A:
The device is not ready.
*blabla* Administrator\Desktop>dir /s C:
Volume in drive C has no label.
有人可以帮我吗?
【问题讨论】:
-
我似乎无法复制这一点。我是否正确阅读了调用
dir /s C:时出现的唯一行是“驱动器 C 中的卷没有标签”还是还有更多? -
尝试 FOR /F "skip=1 delims=" %x in ('wmic logicaldisk get caption') do dir /s %x\*blabla*。 delims 有一个空格作为附加标记。我还在 %x\*blabla* 中添加了一个反斜杠,用于 logicaldisk get caption 只返回驱动器名和冒号,而不是反斜杠
-
这个更好
FOR /F "skip=1 delims= " %x in ('wmic logicaldisk get caption') do echo(%x | find ":">NUL && dir /s %x\*blabla* -
试试这个:
for /F "skip=1" %X in ('wmic LogicalDisk GET Caption') do for /F %Y in ("%X") do dir /S "%Y\*blabla*";嵌套另一个for /F循环以避免wmic命令的Unicode 输出转换导致的伪影... -
你也可以试试这个命令
Where只需输入Where /?
标签: windows batch-file cmd