批处理文件将文件从一台服务器复制到另一台服务器,在进程中添加远程目录到文件名

发布于 2024-11-15 16:06:59 字数 605 浏览 2 评论 0原文

我编写了一个批处理文件来将文件从一台服务器复制到另一台服务器,但是,我需要能够重命名刚刚复制的文件以包含文件夹路径。我想出的完成这项工作的代码是:

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 技术交流群。

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

发布评论

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

评论(1

南冥有猫 2024-11-22 16:06:59

如果您知道文件的深度只有 1 个文件夹,则可以使用以下命令

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 个文件夹深: 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

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

)

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.

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