1

In my PCs I have a series of files that are in the Path C:\Meleena

In some previous installations this path was different (it was C:\second_path\Meleena).

After fixing every computers to the path C:\Meleena I have 2 different scenarios:

  • PC where I have only C:\Meleena
  • PC where I have C:\second_path\Meleena

I might therefore have in C:\Windows\Settings.ini a situation like this:

[Summer]
Meleena=C:\Meleena

or

[Summer]
Meleena=C:\second_path\Meleena

I wonder if a batch file might read from C:\Windows\Settings.ini the [Summer] section and do the following:

  • If Meleena = C:\Meleena do not do anything;

  • If Meleena = C:\second_path\Meleena

Copy all files from C:\Meleena to C:\second_path\Meleena

Is there a possibility to get a batch file to read this section from Settings.ini and do a conditional copy?

Many thanks to all of you.

Meleena

Bali C
  • 30,582
  • 35
  • 123
  • 152
Meleena
  • 89
  • 2
  • 8

2 Answers2

0

This should do it

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
)
)
Bali C
  • 30,582
  • 35
  • 123
  • 152
0

start with parameters: 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

Community
  • 1
  • 1
Ilshat
  • 196
  • 1
  • 1
  • 4