使用xcopy命令提示符记录

时间:2011-01-26 14:33:27

标签: windows command-line dos xcopy

我有一个我正在运行的xcopy脚本,它读取带有目录和文件名的.csv文件并解析它以复制文件。

这是脚本:

echo F | for /f "delims=, tokens=1,2,3" %i in (D:\foo.csv) 
do xcopy /i /d "Z:\%i\%j\%k" "Y:\%i\%j\%k" >> "D:\xcopy\Log.txt"

命令提示符的输出是正在执行的命令:

 echo F   | xcopy /i /d "Z:\hcri001\a1\
ffce5a14-33ca-43cf-b366-af266c450979" "Y:\hcri001\a1\ffce5a14-33ca-43cf-b366
-af266c450979"  1>>"D:\xopy\Log.txt

但是,日志只有命令的输出:

0 File(s) copied
0 File(s) copied
0 File(s) copied
Does Y:\hcri001\2d\545392db-50fa-40d9-aaa2-0892ca5057f3 specify a file name
or directory name on the target
(F = file, D = directory)? F
Z:\hcri001\2d\545392db-50fa-40d9-aaa2-0892ca5057f3
1 File(s) copied

是否有某些命令正在执行,以及输出? 另外,反正有没有我可以放在行首的某种计数器?

我的理想日志文件将采用以下格式:

    1) C:\Desktop>echo F   | xcopy /i /d "Z:\hcri001\a7\
    00a62a73-d7a7-4cfb-b55c-457bc67b3647" "Y:\hcri001\a7\00a62a73-d7a7-4cfb-b55c
    -457bc67b3647"  1>>"D:\Robocopy\AtlusPatient131172CopyLog.txt 
    0 File(s) copied
    2)    C:\Desktop>echo F   | xcopy /i /d "Z:\hcri001\d5\
    003452354-d7a7-4cfb-452c-457bc67b3647" "Y:\hcri001\d5\003452354-d7a7-4cfb-452c-457bc67b3647"  1>>"D:\Robocopy\AtlusPatient131172CopyLog.txt 
    0 File(s) copied
    3)   C:\Desktop>echo F   | xcopy /i /d "Z:\hcri001\2d\545392db-50fa-40d9-aaa2-0892ca5057f3" "Y:\hcri001\2d\545392db-50fa-40d9-aaa2-0892ca5057f3"  1>>"D:\Robocopy\AtlusPatient131172CopyLog.txt 
Does Y:\hcri001\2d\545392db-50fa-40d9-aaa2-0892ca5057f3 specify a file name
        or directory name on the target
        (F = file, D = directory)? F
        Z:\hcri001\2d\545392db-50fa-40d9-aaa2-0892ca5057f3
        1 File(s) copied
如果命令可以修剪为仅包含文件名而不是整个命令,即1) "Z:\hcri001\2d\545392db-50fa-40d9-aaa2-0892ca5057f3" 0 File(s) copied

,则可获得

和奖励积分

1 个答案:

答案 0 :(得分:2)

for /f "delims=, tokens=1,2,3" %i in (D:\foo.csv) do (
  echo xcopy /i /d "Z:\%i\%j\%k" "Y:\%i\%j\%k" >> "D:\xcopy\Log.txt"
  echo f | xcopy /i /d "Z:\%i\%j\%k" "Y:\%i\%j\%k" >> "D:\xcopy\Log.txt"
)

对于计数器,您需要SETLOCAL ENABLEEXTENSIONS然后set counter=1 并在循环set /a counter=!counter! + 1