Page 1 of 1 1
Topic Options
#125180 - 2004-08-17 09:35 PM Is there a smarter way of doing this?
operez Offline
Getting the hang of it

Registered: 2003-08-08
Posts: 75
Is there a smarter way of doing this? What I am trying to do is first check for the existence of the WinDart.ini file in the users S:\Windows folder. If it exists I want to verify that the INI file has all three sections. If the INI file is missing a section, I check for the existence of the backup file (in Citrix the extension is .ctx) and verify that it has all three sections. If it does then I use the backup. If it doesn’t I use a generic template file and copy it to the user’s S:\Windows folder.

If the WinDart.ini file does not exist, I check for the existence of the backup file. Well, you see what I’m doing. Just seems to me that I could be using less code to perform the repetition.

Code:

If Exist ("S:\Windows\WinDart.ini")
$RC = ReadProfileString("S:\Windows\WinDart.ini","","")
If InStr($RC,"ENV") And InStr($RC,"Shell") And InStr($RC,"Components")
? "WinDart.ini file checks out OK"
Else
If Exist ("S:\Windows\WinDart.ctx")
$RC = ReadProfileString("S:\Windows\WinDart.ctx","","")
If InStr($RC,"ENV") And InStr($RC,"Shell") And InStr($RC,"Components")
? "WinDart.ctx file being copied to WinDart.ini"
Shell 'cmd /c Copy "S:\Windows\WinDart.ctx" "S:\Windows\WinDart.ini" >nul 2>&1'
Else
Shell 'cmd /c Copy "F:\Template\WinDart\WinDart.ini" "S:\Windows" >nul 2>&1'
EndIf
EndIf
EndIf
Else
If Exist ("S:\Windows\WinDart.ctx")
$RC = ReadProfileString("S:\Windows\WinDart.ctx","","")
If InStr($RC,"ENV") And InStr($RC,"Shell") And InStr($RC,"Components")
? "WinDart.ctx file being copied to WinDart.ini"
Shell 'cmd /c Copy "S:\Windows\WinDart.ctx" "S:\Windows\WinDart.ini" >nul 2>&1'
Else
Shell 'cmd /c Copy "F:\Template\WinDart\WinDart.ini" "S:\Windows" >nul 2>&1'
EndIf
EndIf
EndIf


Top
#125181 - 2004-08-17 11:40 PM Re: Is there a smarter way of doing this?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, you can remove the if-exists lines.
readprofilestring will just output empty line if the file does not exist.
_________________________
!

download KiXnet

Top
#125182 - 2004-08-18 05:16 AM Re: Is there a smarter way of doing this?
Anonymous
Unregistered


You’re right. Not finding the correct number of sections could be the results of not finding the file and by removing the first “If Exist” I was able to eliminate the “Else” and the second set of commands. Sometimes you just need another pair of eyes to help you see that the answer to your problem is right in front of you.

Many Thanks.

Top
#125183 - 2004-08-18 08:49 AM Re: Is there a smarter way of doing this?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
You could also use the native COPY command from KiXtart without shelling out.
Top
#125184 - 2004-08-18 09:36 AM Re: Is there a smarter way of doing this?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
did some rewrite to see the whole picture...
you used instring but that kinda is untrustable, as there could be similar section-names.
with ascan we get exact matches.
this is what I got:
Code:

$RC = split(ReadProfileString("S:\Windows\WinDart.ini","",""),chr(10))
If -1<ascan($RC,"ENV") and -1<ascan($RC,"Shell") and -1<ascan($RC,"Components")
? "WinDart.ini file checks out OK"
Else
$RC = split(chr(10)+ReadProfileString("S:\Windows\WinDart.ctx","",""),chr(10))
If -1<ascan($RC,"ENV") and -1<ascan($RC,"Shell") and -1<ascan($RC,"Components")
? "WinDart.ctx file being copied to WinDart.ini"
Copy "S:\Windows\WinDart.ctx" "S:\Windows\WinDart.ini"
Else
Copy "F:\Template\WinDart\WinDart.ini" "S:\Windows"
EndIf
EndIf

_________________________
!

download KiXnet

Top
#125185 - 2004-08-18 05:20 PM Re: Is there a smarter way of doing this?
Anonymous
Unregistered


Thanks Jooel, that'll work too. Again, Thanks for helping me learn something new.
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Henriques) and 2516 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.061 seconds in which 0.03 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org