使用 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 个文件
I have an xcopy script that I'm running that reads in a .csv file with directories and file names and parses it to copy the files.
Here's the script:
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"
The output to the command prompt are the commands being executed:
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
However, the log just has the output of the commands:
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
Is there someway to have both the commands being executed, as well as the output?
Also, is there anyway to have some sort of counter that I can put in the beginning of the line?
My Ideal log file would be in this format:
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
and bonus points if the command can be trimmed to just include the file name instead of the whole command i.e. 1) "Z:\hcri001\2d\545392db-50fa-40d9-aaa2-0892ca5057f3"
0 File(s) copied
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于计数器,您需要
SETLOCAL ENABLEEXTENSIONS
,然后set counter=1
并在循环内
set /a counter=!counter! + 1
For the counter you need
SETLOCAL ENABLEEXTENSIONS
thenset counter=1
and inside the loop
set /a counter=!counter! + 1