Board logo

标题: [文件操作] 批处理路径带空格的问题,求大佬指教 [打印本页]

作者: chajiahuo2    时间: 2020-7-27 18:34     标题: 批处理路径带空格的问题,求大佬指教

代码如下:
  1. ::@echo off
  2. for %%a in (c d e f g h) do (
  3. for /f "delims=" %%b in ('dir/ad/s/b "%%a:\"^|findstr /i  "YYhelper_DC - lgdyf$"') do (cd /d %~dp0
  4. copy "*.*" "%%b\" >nul 2>nul
  5. )
  6. )
  7. pause
复制代码
实现历遍 c d e f g h盘符,找到yyhelper_DC - lgdyf文件夹,然后从批处理所在目录向找到的所有yyhelper_DC - lgdyf文件夹复制全部文件

但是执行失败了 到底哪里的问题
作者: smss    时间: 2020-7-27 20:07

本帖最后由 smss 于 2020-7-27 20:13 编辑
  1. for %%a in (c d e f g h)do if exist %%a:\ for /f "delims=" %%b in ('dir/ad/s/b "%%a:\*YYhelper_DC - lgdyf*"')do copy "*.*" "%%b\"
复制代码
可以找到第一个就跳转 从而提高效率
  1. for %%a in (c d e f g h)do if exist %%a:\ for /f "delims=" %%b in ('dir/ad/s/b "%%a:\*YYhelper_DC - lgdyf*"')do set "b=%%b"&goto 1
  2. :1
  3. copy "*.*" "%b%\"
复制代码

作者: Batcher    时间: 2020-7-27 20:09

回复 1# chajiahuo2


带空格的字符串试试 /c 参数
findstr /i /c:"YYhelper_DC - lgdyf"
作者: chajiahuo2    时间: 2020-7-28 09:26

回复 3# Batcher

不行哦 报错 提示系统找不到指定路径
作者: chajiahuo2    时间: 2020-7-28 09:42

回复 2# smss


   用你的成功了 我想知道为什么 findstr不成功
作者: Batcher    时间: 2020-7-28 11:15

回复 4# chajiahuo2


参考 Q-01 的方法看看是 findstr 在报错还是 copy 在报错
https://mp.weixin.qq.com/s/6lbb97qUOs1sTyKJfN0ZEQ
作者: smss    时间: 2020-7-28 11:45

回复 5# chajiahuo2
没必要
  1. for %%a in (c d e f g h)do if exist %%a:\ for /f "delims=" %%b in ('dir/ad/s/b "%%a:\" ^|find "YYhelper_DC - lgdyf"')do copy "*.*" "%%b\"
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2