Sign in to follow this  
Followers 0
korsg

Arraying ini file ?

3 posts in this topic

Hello i am making a little backup script at my work that copies specific files from different network places.

I made an GUI as an control panel that writes the IP adresses of locations to a INI file..

Heres a little view of the ini file:

(backup.ini)

------------------------------

[1]

IP=\\172.16.23.10\hc

[2]

IP=\\172.16.22.10\hc

[3]

IP=\\172.16.21.10\hc

[4]

IP=\\172.16.4.10\hc

[5]

IP=\\172.16.14.10\hc

[6]

IP=\\172.16.2.10\hc

-------------------------------

And then one of my attempts look like this

$source = IniRead("C:\Backup\backup.ini", "1", "IP","error")
$dest = "C:\backup"
 
 
$var = IniReadSectionNames("C:\Backup\backup.ini")
If @error Then 
    MsgBox(4096, "", "Error occured, probably no INI file.")
Else
    For $i = 1 To $var[0]
    $var = RunWait(@ComSpec & ' /c xcopy "'& $source & '"\file.exe"' & '" "' & $dest & '"  /Y',@TempDir)
    Next
EndIf

But this attempt just loops the coping of destination 1.

Just to make it clear the goal of my script is to read all the IP adresses of the INI file and copy the chosen files from every location to a local directory.

I cant figure out how the array thing work, even though been searching through forums and help file, so i really hope you can help me.. :P

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

$source = IniRead("C:\Backup\backup.ini", "1", "IP","error")
$dest = "C:\backup"


$var = IniReadSectionNames("C:\Backup\backup.ini")
If @error Then
    MsgBox(4096, "", "Error occured, probably no INI file.")
Else
    For $i = 1 To $var[0]
    $copy = RunWait(@ComSpec & ' /c xcopy "'& $source & '"\file.exe"' & '" "' & $dest & '"  /Y',@TempDir)
    Next
EndIf

Just don't mess with $var if you still use it. :P

Edited by dabus

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

This should work for you....

$dest = "C:\backup"

$var = IniReadSectionNames("C:\Backup\backup.ini")
If @error Then 
    MsgBox(4096, "", "Error occured, probably no INI file.")
Else
   For $i = 1 To $var[0]
      $source = IniRead("C:\Backup\backup.ini", $var[$i], "IP","error")
      If $source <> 'error' Then
         RunWait(@ComSpec & ' /c xcopy "'& $source & '"\file.exe"' & '" "' & $dest & '" /Y',@TempDir)
     EndIf
   Next
EndIf

Edit: Fixed Typo

I will replace this line $var = RunWait(@ComSpec & ' /c xcopy "'& $source & '"\file.exe"' & '" "' & $dest & '" /Y',@TempDir)

for this one FileCopy($source & '\file.exe', $dest, 9)

Edited by Danny35d

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0