Jump to content

Filewriteline question


lyledg
 Share

Recommended Posts

I am trying to do 2 things here.

Code Snippet...

$apppath = GuiCtrlCreateInput("", 200, 60, 240, 20)
$Regfile = FileOpen(@Scriptdir &  "\test.reg", 1)

; Check if file opened for reading OK
If $Regfile = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
    
Else



1) Filewriteline($regfile, "[HKEY_LOCAL_MACHINE\SOFTWARE\Installer\Install[Need to put a number here which increments by one each time when this same line is appened to the reg file"]

2) Filewriteline($regfile, '"Command"="' & GUICtrlread($apppath) & '"')

In point number 2), This line is going to contain a path, and more likely always from a UNC path which means more than one backslash will appear. But in a exported *.reg file, the path always must have" \\" (2 backslashes) rather than one..

How do I do a search and replace on this line only, replacing the "\" (single backslashes), with double ones "\\" ?

I have this line but know it is not right..any help would be appreciated please

$File = StringReplace('"Command"="' & GUICtrlread($apppath) & '"', "\", "\\")

Thanx

Link to comment
Share on other sites

Here is something:

If StringInStr("\\", $TestUNCPath) Then
 ;Done
Else
  StringReplace($TestUNCPath, "\", "\\", 1)
EndIf

This replaces only the first occurance and only if nec.

Did I understand your q?

J

If I am too verbose, just say so. You don't need to run on and on.

Link to comment
Share on other sites

Thanks guys for the replies...

Lazycat, I think you are right...the writing out of the file should still be ok...I was under the impression that if a exported reg file HAD to have "\\" in any given path statement, but after some more testing I see it should be ok

But, any ideas how I could do the following:

1) Filewriteline($regfile, "[HKEY_LOCAL_MACHINE\SOFTWARE\Installer\Install
(Need to put a number here which increments by one each time when this same line is appened to the reg file")

Example:

[HKEY_LOCAL_MACHINE\SOFTWARE\Installer\Install0]

[HKEY_LOCAL_MACHINE\SOFTWARE\Installer\Install1]


[HKEY_LOCAL_MACHINE\SOFTWARE\Installer\Install2]

etc

Many thanks

Link to comment
Share on other sites

Hmm, what the "same line" you want to write? :idiot: This should be exactly "HKEY_LOCAL_MACHINE\SOFTWARE\Installer\Install"? Need a bit more explanation, what the line you will take and how you want to transform it. But anyway, probably you need load all regfile and search for existence of needed line, or use ini read functions.

Link to comment
Share on other sites

To add the number at the end is easy.

Just have a "global" variable initialized to 0

dim $WriteLineCt = 0

which increments each time you go through the write process.

$WriteLineCt = $WriteLineCt + 1

And at the end of your string you are trying to write, tack on:

StringTrimRight($YourOriginalString, 1) & String($WriteLineCt) & "]"

Here is something to keep things neat (Here supporting 99 lines):

;^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v

Func Int2_2DigitStr($AnInteger)
  If $AnInteger < 0 Or ($AnInteger > 99) Then
   ;Error!!
  EndIf
  
  If $AnInteger < 10 Then
    Return "0" & String($AnInteger)
  Else
    Return String($AnInteger)
  EndIf
EndFunc  ;==>Int2_2DigitStr
;^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v

J

If I am too verbose, just say so. You don't need to run on and on.

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...