批处理文件从一台服务器的文件复制到其他添加远程目录中的进程文件名 [英] batch file to copy files from one server to other adding remote directory to filename in process
问题描述
我写一个批处理文件从一台服务器复制到另一个文件,但是,我需要能够重新命名刚才复制到包含文件夹路径的文件。在code I纷纷拿出做的工作是:
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:
我:\\ w3svc98435783475 \\ ex110430.log
i:\w3svc98435783475\ex110430.log
和我想要做的就是把它复制到D:\\ ServerLogsAndBackups \\ IIS \\ W1 \\ 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.
非常感谢
推荐答案
如果您知道这些文件的深度只有1文件夹,可以使用以下
If you know the depth of the files are only 1 folder in, you can use the following
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 (
FOR /F "tokens=1-2 delims=\" %%H IN ("%%~pnxG") DO (
XCOPY %%G D:\ServerLogsAndBackups\IIS\w%%i\%%H_%%I
)
)
7z a -t7z D:\ServerLogsAndBackups\IIS\w%%i\files%%i.7z *.log -mx9
net use i: /delete
)
如果该文件是深文件夹的一组数字,你可以根据需要深调整令牌和添加额外的字母XCOPY命令结束时(即5个文件夹:令牌= 6和XCOPY命令这将是% %H _ %%我_ %%Ĵ_ %% K表_ %%大号_ %% M)
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.
这篇关于批处理文件从一台服务器的文件复制到其他添加远程目录中的进程文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!