2016-08-02 46 views
0

我试图寻找所有驱动器的文件名。当单独使用dir命令一切顺利:变量和通配符批量和cmd.exe的

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. 

有人能帮助我吗?

+0

我似乎无法复制此。我是否正确读取,调用'dir/s C:'时出现的唯一行是“驱动器C中的卷没有标签”,还是有更多? – SomethingDark

+0

尝试_FOR/F“skip = 1 delims =”%x in('wmic logicaldisk get caption')do dir/s%x \\ * blabla * _。 _delims_有一个空格作为附加标记。也是我在_%×\\ *布拉布拉* _添加一个反斜杠用于_logicaldisk获得图片说明只返回DRIVENAME和结肠,而不是反斜杠 – elzooilogico

+0

这是更好的'FOR/F “跳过= 1个delims =” %在('WMIC逻辑磁盘X获得标题 ')做回声(%X |找到 “:”> NUL && DIR/S%X \ *布拉布拉*' – elzooilogico

回答

0

感谢您的帮助,以及对其他脚本的精彩创意。

哪里是我一直在寻找的答案:

C:\>FOR /F "skip=1 delims= " %x in ('wmic logicaldisk get caption') do @where /R %x *blabla* 2>NULL 
C:\Users\Administrator\Desktop\blabla.txt 
+0

记那'where'只有在'%路径%'变量的文件夹样子。如果你的文件是在其他地方,你需要的'dir'解决方案之一(我想补充的'/ B'开关) – Stephan