You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改批处理脚本,实现向列表内电脑批量复制文件并检查双目标路径

Fixing the Batch Script to Copy to Both 32-bit and 64-bit Paths When They Exist

Got it, let's tackle this. The core issue with your original script is the mutually exclusive IF ELSE structure — it only checks the 64-bit path if the 32-bit path doesn't exist. To make it run both copies when both paths are present, we just need to split the two checks into separate, independent IF statements instead of chaining them with ELSE.

Here's the revised, optimized script:

For /F "usebackq tokens=*" %%a in ("C:\Test\PCList.txt") Do (
    :: Check for 32-bit target path and run copy if it exists
    IF Exist "\\%%a\%Target32%" (
        robocopy "%source32%" "\\%%a\%Target32%" /tbd /s /is /ndl /nfl /log+:"%logdir%\%%a_x86_%date:~10,4%.%date:~7,2%.%date:~4,2%.log"
    )
    :: Check for 64-bit target path and run copy if it exists (no ELSE, so runs independently)
    IF Exist "\\%%a\%Target64%" (
        robocopy "%source64%" "\\%%a\%Target64%" /tbd /s /is /ndl /nfl /log+:"%logdir%\%%a_x64_%date:~10,4%.%date:~7,2%.%date:~4,2%.log"
    )
)

Key Changes Explained:

  • Removed the ELSE between the two path checks: Now each IF executes on its own. If both \\%%a\%Target32% and \\%%a\%Target64% exist on a machine, both robocopy commands will run for that device.
  • Added inline comments (::) to make the script easier to maintain for your team — small touches like this save time down the line when someone needs to tweak the script.

Optional Reliability Optimization:

Your current log filename uses %date%, which depends on the system's regional date settings. If some machines use a format with slashes (like MM/DD/YYYY), those slashes will break the filename. To fix this, you can generate a consistent date string with PowerShell (built into all modern Windows systems):

:: Get a universal YYYY-MM-DD date string first
For /F "delims=" %%d in ('powershell -Command "(Get-Date).ToString('yyyy-MM-dd')"') Do Set "logDate=%%d"

:: Then use this consistent date in your log paths
/log+:"%logdir%\%%a_x86_%logDate%.log"
/log+:"%logdir%\%%a_x64_%logDate%.log"

This ensures your log files always have a valid, uniform name no matter what regional settings the target machines use.

内容的提问来源于stack exchange,提问作者MatrixMs Merlin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 05:25:49