1

我有一个正在运行的 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

4

1 回答 1

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

于 2011-01-27T05:32:05.817 回答