【问题标题】:How to make array list in my case using Batch File Script?在我的情况下,如何使用批处理文件脚本制作数组列表?
【发布时间】:2022-01-13 07:11:21
【问题描述】:

我想将文件从一个文件夹复制到本地网络中的多台电脑。

我想在下面的数组列表中添加 IP 地址

set list=\\192.168.55.102
set list=%list%;\\192.168.55.103 
set list=%list%;\\192.168.55.104 
set list=%list%;\\192.168.55.105
set list=%list%;\\192.168.55.106

然后,我将通过以下代码将文件复制到上述IP。但以下代码适用于 1 个 ip。它正在工作并将文件复制到目标位置

net use "\\192.168.55.102\c$\foldername" /user:%username% %password%
:copy
copy "C:\Desktop\Update" "\\192.168.55.102\c$\foldername"
IF ERRORLEVEL 0 goto disconnect
goto end
:disconnect 
net use "\\192.168.55.102\c$\foldername" /delete
goto end
:end

我尝试了下面的方法,但它不起作用

@echo off
for %a% in (%list%) do (  
    net use %a%\foldername /user:%username% %password%
    :copy
    copy "C:\Desktop\Update" %a%\foldername
    IF ERRORLEVEL 0 goto disconnect
    goto end
    :disconnect 
    net use %a%\foldername /delete
    goto end
    :end
)

【问题讨论】:

    标签: batch-file script windows-scripting


    【解决方案1】:

    创建一个变量(不是数组)并添加 IP,以空格、逗号或分号分隔。然后连接到IPC$ 以允许身份验证,复制文件,然后删除IPC$ 共享:

    @echo off
    set "list=192.168.55.102 192.168.55.103 192.168.55.104 192.168.55.105 192.168.55.106"
    for %%i in (%list%) do (
        net use "\\%%i\IPC$" /user:%username% %password%
        copy "C:\Desktop\Update" "\\%%i\foldername"
        net use /d "\\%%i\IPC$"
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-12
      • 1970-01-01
      • 2015-02-01
      • 1970-01-01
      • 2012-10-30
      • 1970-01-01
      • 1970-01-01
      • 2016-03-30
      相关资源
      最近更新 更多