找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 28876|回复: 6

[文件操作] 批处理路径带空格的问题,求大佬指教

[复制链接]
发表于 2020-7-27 18:34:15 | 显示全部楼层 |阅读模式
代码如下:
  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文件夹复制全部文件

但是执行失败了 到底哪里的问题
发表于 2020-7-27 20:07:23 | 显示全部楼层
本帖最后由 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%"
复制代码
发表于 2020-7-27 20:09:59 | 显示全部楼层
回复 1# chajiahuo2


带空格的字符串试试 /c 参数
findstr /i /c:"YYhelper_DC - lgdyf"
 楼主| 发表于 2020-7-28 09:26:08 | 显示全部楼层
回复 3# Batcher

不行哦 报错 提示系统找不到指定路径
 楼主| 发表于 2020-7-28 09:42:55 | 显示全部楼层
回复 2# smss


   用你的成功了 我想知道为什么 findstr不成功
发表于 2020-7-28 11:15:10 | 显示全部楼层
回复 4# chajiahuo2


参考 Q-01 的方法看看是 findstr 在报错还是 copy 在报错
https://mp.weixin.qq.com/s/6lbb97qUOs1sTyKJfN0ZEQ
发表于 2020-7-28 11:45:19 | 显示全部楼层
回复 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"
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-20 04:04 , Processed in 0.018008 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表