Board logo

标题: [其他] 批处理拷贝文件为什么无法成功? [打印本页]

作者: sfzl88h    时间: 2014-4-24 11:50     标题: 批处理拷贝文件为什么无法成功?

  1. @echo off
  2. title 【文件备份】拷贝中...
  3. for /f "tokens=15" %%a in ('ipconfig ^| find /i "IP Address"') do  echo %%a &md %computername%-%%a &XCOPY /s/e/i/y d:\*.txt %computername%-%%a
复制代码
为什么无法拷贝成功?
作者: 522235677    时间: 2014-4-24 16:27

XCOPY是复制文件夹的
用copy试试
作者: sfzl88h    时间: 2014-4-24 16:35

回复 2# 522235677

我要拷贝这个文件夹下所有文件夹和文件……必须用XCOPY……这个不成功和COPY命令无关
作者: sfzl88h    时间: 2014-4-24 16:36

回复 2# 522235677


问题出在最后的变量上……我把-%%a去掉就可以
但我想以计算机+IP命令
作者: 522235677    时间: 2014-4-24 16:46

回复 4# sfzl88h
  1. for /f "tokens=15" %%a in ('ipconfig ^| find /i "IP Address"') do  (
  2.    echo %%a
  3.    md %computername%-%%a
  4.    XCOPY /s/e/i/y d:\*.txt %computername%-%%a
  5. )
复制代码

作者: apang    时间: 2014-4-24 18:50

在我的机器上,显示的是这个样子:
后面的引号消失,应该是获取的%a后面存在回车符所致

这样可以:
  1. @echo off
  2. for /f "tokens=15" %%a in ('ipconfig ^| find /i "IP Address"') do (
  3.     for /f "delims=" %%b in ("%computername%-%%a") do (
  4.         xcopy /s /y d:\*.txt "%%~nxb\"
  5.     )
  6. )
  7. pause
复制代码

作者: 522235677    时间: 2014-4-24 18:57

回复 6# apang


    你咋还在PE里? 他的原代码我测试都没问题
作者: apang    时间: 2014-4-24 19:12

回复 7# 522235677


    虚拟机里,没有xp
win7测试没有问题




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