使用 xcopy 命令提示符记录日志

发布于 2024-10-14 02:17:55 字数 1887 浏览 4 评论 0原文

我正在运行一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那些过往 2024-10-21 02:17:55
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

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"
)

For the counter you need SETLOCAL ENABLEEXTENSIONS then set counter=1
and inside the loop set /a counter=!counter! + 1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文