Jump to content

Re-Name Duplicate String in File


Recommended Posts

What I'm  trying to do is rename a duplicate string in a file to make it unique. using _ReplaceStringInFile I am able to rename the first occurrence or all occurrences. Any suggestions how to alter my code to rename following occurrences until all instances have been changed.

$file = @ScriptDir & "\test.ini"
Global $sharename =  IniReadSection ($file,"PrintList")

For $x = 1 to UBound ($sharename) -1
    If String ($sharename[$x][0]) = "ShareName" Then
        $str_replace = _ReplaceStringInFile ($file,"ShareName","ShareName0" &+ 1 ,1,0)
        If $str_replace = 1 Then
            ExitLoop
        EndIf
    EndIf
Next

ShellExecute ($file) ; to Verify Change to Document

 

test.ini

Link to comment
Share on other sites

NVM Figured it out... couldn't Use ShareName as both search string and replace string.

Modified:

$str_replace = _ReplaceStringInFile ($file,"ShareName","ShareName0" &+ 1

To:

$str_replace = _ReplaceStringInFile ($file,"ShareName","PrintName0" & $x ,1,0)

and all values were modified appropriately.

Link to comment
Share on other sites

This example appears to work.

#include <File.au3>

Local $iDup = 0
$file = "test.ini"
Global $sharename = IniReadSection($file, "PrintList")

For $x = 1 To UBound($sharename) - 1
    If String($sharename[$x][0]) = "ShareName" Then
        $iDup += 1
        $sharename[$x][0] &= StringRight("00" & $iDup, 2)
    EndIf
Next
IniWriteSection($file, "PrintList", $sharename)

ShellExecute($file) ; to Verify Change to Document"

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...