【问题标题】:Batch file conditional copy after ini readingini读取后的批处理文件条件复制
【发布时间】:2013-01-08 04:40:03
【问题描述】:

在我的 PC 中,我有一系列位于路径 C:\Meleena 中的文件

在以前的一些安装中,这个路径是不同的(它是C:\second_path\Meleena)。

在将每台计算机修复到路径 C:\Meleena 之后,我有两种不同的情况:

  • 我只有C:\Meleena的PC
  • 我有C:\second_path\Meleena的PC

因此,我在C:\Windows\Settings.ini 中可能会遇到这样的情况:

[Summer]
Meleena=C:\Meleena

[Summer]
Meleena=C:\second_path\Meleena

我想知道批处理文件是否可以从C:\Windows\Settings.ini[Summer] 部分读取并执行以下操作:

  • 如果Meleena = C:\Meleena 什么都不做;

  • 如果Meleena = C:\second_path\Meleena

将所有文件从C:\Meleena复制到C:\second_path\Meleena

是否有可能获得一个批处理文件来从Settings.ini 读取此部分并进行条件复制?

非常感谢大家。

梅莱娜

【问题讨论】:

    标签: batch-file conditional ini


    【解决方案1】:

    从参数开始:C:>ini.bat settings.ini Summer Meleena C:\Meleena

    ini.bat:

    @setlocal enableextensions enabledelayedexpansion
    @echo off
    set file=%~1
    set area=[%~2]
    set key=%~3
    set val=%~4
    set currarea=
    for /f "usebackq delims=" %%a in ("!file!") do (
        set ln=%%a
        if "x!ln:~0,1!"=="x[" (
            set currarea=!ln!
        ) else (
            for /f "tokens=1,2 delims==" %%b in ("!ln!") do (
                set currkey=%%b
                set currval=%%c
                if "x!area!"=="x!currarea!" if "x!key!"=="x!currkey!" (
                    if not "x!val!"=="x!currval!" (
                        echo !currval!
                        xcopy !val! !currval! /H /E /G /Q /R /Y
                    )
                )
            )
        )
    )
    endlocal
    

    Read ini from windows batch file

    【讨论】:

      【解决方案2】:

      应该这样做

      for /f "skip=2" %%a in ('find /v "[Summer]" C:\Windows\Settings.ini') do (
      if "%%a"=="C:\second_path\Meleena" (
      xcopy C:\Meleena C:\second_path\Meleena
      )
      )
      

      【讨论】:

        猜你喜欢
        • 2015-09-13
        • 2011-02-21
        • 2015-01-13
        • 2014-08-06
        • 1970-01-01
        • 1970-01-01
        • 2013-09-23
        • 2011-09-28
        • 1970-01-01
        相关资源
        最近更新 更多