MOVE操作后批量制作日志文件 [英] Making log file in batch after a MOVE operation

查看:98
本文介绍了MOVE操作后批量制作日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要一些帮助来为当前正在运行的批处理脚本创建日志文件.当我将文件从一台服务器移到另一台服务器时,很容易知道何时将文件移到另一端.

I just need some help with creating a log file for a batch script I'm running at the moment. As I move files from 1 server to another it would be handy to know when things have been moved over.

此刻,我尝试了一些操作,例如:

At the moment I've tried a few things like:

if %errorlevel% GTR 0 (echo MOVE FAILURE>Logs\log.txt) else (echo MOVE SUCCESSFUL>Logs\log.txt)

但这只是草率的代码,因为我必须在每一行之后加上它,并且它不会告诉我我刚刚移动的文件的名称.

But this just gets to be sloppy code, as I would have to put it after every line, and it doesn't tell me the name of the file I have just moved.

此刻是我的代码:

@Echo OFF

cd C:\Test

MOVE "Home\*.*" "Work"

Echo COMPLETE
Pause

当然还有更多的行,大约还有20行,但是为了进行测试,我只有一个文件夹,并且文件夹名称只是安慰剂.

Of course there's more lines, about another 20, but for the sake of testing I just have the one folder, and the folder names are just placebos.

现在我可以通过移动命令"使用默认的返回屏幕

Now I can use the default return screen by the Move Command

C:\Test\Home\Test.txt
    1 file(s) moved.

但是我不知道如何将输出结果移动到一个简单的.txt文件中,而我只需保留一个记录即可.

But I don't know how to move that output into a simple .txt file that I can just keep a record off.

如果有更好的方法或更好的程序编写它,请告诉我,我将进行调查!

By the way if there a better way or better program to write it in let me know, and I'll investigate!

推荐答案

dbenham的礼貌:您应该研究ROBOCOPY命令.它具有移动文件的选项,并且可以提供已完成操作的完整日志.

Courtesy of dbenham : You should investigate the ROBOCOPY command. It has options to move files, and it can give a complete log of what was done.

robocopy "Home" "Office" /MOV /NJH /NP /NS /NC /LOG+:"Desktop\Log-%date:/=%-%time:~0,2%;%time:~3,2%.txt"

是我用过的!效果不错,虽然不完美,但可以让我监督已移动的内容!

is what I've used! Works fine, not perfect but give me oversight into what has been moved!

这篇关于MOVE操作后批量制作日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆