批处理文件将文件从一台服务器复制到另一台服务器,在进程中添加远程目录到文件名
我编写了一个批处理文件来将文件从一台服务器复制到另一台服务器,但是,我需要能够重命名刚刚复制的文件以包含文件夹路径。我想出的完成这项工作的代码是:
ECHO OFF
SETLOCAL EnableDelayedExpansion
set include=*.log
FOR /L %%i IN (1,2,3) DO (
net use i: \\my-server%%i\d$\IISLogs
FOR /R i:\ %%G IN (%include%) DO (
XCOPY %%G D:\ServerLogsAndBackups\IIS\w%%i\
)
7z a -t7z D:\ServerLogsAndBackups\IIS\w%%i\files%%i.7z *.log -mx9
net use i: /delete
)
该文件将来自以下内容:
i:\w3svc98435783475\ex110430.log
我想要做的是将其复制到 D:\ServerLogsAndBackups\IIS\w1\w3svc98435783475_ex110430 。日志。我不确定如何将遥控器上的目录路径放入文件名中。
非常感谢
I've written a batch file to copy files from one server to another, however, i need to be able to rename the file just copied to contain the folder path. The code i have come up with to do the job is:
ECHO OFF
SETLOCAL EnableDelayedExpansion
set include=*.log
FOR /L %%i IN (1,2,3) DO (
net use i: \\my-server%%i\d$\IISLogs
FOR /R i:\ %%G IN (%include%) DO (
XCOPY %%G D:\ServerLogsAndBackups\IIS\w%%i\
)
7z a -t7z D:\ServerLogsAndBackups\IIS\w%%i\files%%i.7z *.log -mx9
net use i: /delete
)
The file would be coming from something like:
i:\w3svc98435783475\ex110430.log
And what I want to do is copy it into D:\ServerLogsAndBackups\IIS\w1\w3svc98435783475_ex110430.log. I'm unsure how to get the directory path on the remote to put into the filename.
many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您知道文件的深度只有 1 个文件夹,则可以使用以下命令
如果文件的深度为一定数量的文件夹,您可以根据需要调整标记,并在 XCOPY 命令的末尾添加其他字母(即5 个文件夹深: tokens=6 并且在 XCOPY 命令中它将是 %%H_%%I_%%J_%%K_%%L_%%M)
但是,如果文件夹深度混合,您可能会更好调查使用批处理脚本以外的其他方法来完成此操作。
If you know the depth of the files are only 1 folder in, you can use the following
If the files are a set number of folders deep, you can adjust the tokens as required and add additional letters to the end of the XCOPY command (i.e. 5 folders deep: tokens=6 and in the XCOPY command it will be %%H_%%I_%%J_%%K_%%L_%%M)
However, if there is a mix of folder depths, you may be better off looking into using something other than Batch scripting to accomplish this.