Robocopy并获取复制的文件名

Robocopy并获取复制的文件名

本文介绍了Robocopy并获取复制的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用robocopy仅同步更新的文件,但是我还需要获取要复制的文件名.

I'm using robocopy to only sync only newer file, but I also need to get the file name being copied.

我必须进一步使用复制的文件名在另一个文件中进行输入.

I've to further use copied file name to make a entry in a some other file.

我找不到开关,它仅显示复制的文件名,批处理文件的任何powershell脚本也都可以.

I wasn't able to found switch, which only displays copied file name, any powershell script of batch file will also be fine.

推荐答案

user182904,

user182904,

我已经修改了答案,以满足您的要求.

I have revised my answer to suit your requirements.

尝试以下cmd文件.

1)它会从robocopy创建一个日志文件,其中只复制文件夹\文件.

1) It will create a log file from robocopy with just folders\files copied.

2)然后它将把该日志文件剥离为仅复制的文件.

2) It will then strip that log file to just the files copied.

@echo off

rem source folders for robocopy
set source="c:\test\files"
set destin="c:\test\files2"

rem logfile names
set sourcelogfile=log-from-robocopy.txt
set destinlogfile=log-just-files.txt

rem robocopy command to output files copied
robocopy %source%  %destin% /e  /LOG:"%sourcelogfile%" /NP /NS /NC /NDL /TEE /NJH /NJS

rem for loop through robocopy output and stip it down to just file names into new logfile
for /f "tokens=*" %%i in (%sourcelogfile%) do (
    for /f "delims=" %%f in ("%%i") do (
        echo %%~nxf >> %destinlogfile%
    )
)

rem end of code

您可以将选项添加到Robocopy行,但是需要在该行的末尾添加选项,以输出日志文件的其余部分将解析的日志文件.

You can add your options to the Robocopy line, but you will need the options added at the end of that line, to output a log file that the rest of the script will parse.

希望有帮助.

所有robocopy开关的详细信息可以在这里找到:

Details of all the robocopy switches can be found here:

来源: http://ss64.com/nt/robocopy.html

这篇关于Robocopy并获取复制的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 13:35