Page 1 of 1 1
Topic Options
#148517 - 05/09/27 01:02 AM Script Check Please: Use of FOR EACH
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 05/06/15
Posts: 506
Loc: Oregon, USA
Could someone check my script and tell me if it is structured properly?

Code:
  
$sourceDir = 'V:\hotfixes\CAD to RMS fix files\'
$destDir1 = 'C:\Program Files\Common Files\Borland Shared\BDE\'
$destDir2 = '%windir%\system32\'
$checkFile = 'DONOTDELETE-CADFix1.txt'
$sourceFiles1 = 'sql_mss','sqllnk32.cnt','sqllnk32.fts','sqllnk32.hlp','SQLLNK32.TOC','sqlmss32.dll'
$sourceFiles2 = 'ntwdblib.dll'

IF left(@wksta,2) = "PD"
$Result = EXIST($destdir2 + $checkFile)
IF $Result = 0
for each $File1 in $sourceFile1
copy $sourceDir + $File1 $destDir1 + $File1
next
copy $sourceDir + SourceFile2 @destDir2 + sourceFile2
next
copy $sourceDir + $checkFile $destDir2 + $checkFile
ENDIF
ENDIF


Specifically, I'm not sure if my use of FOR EACH and NEXT is correct after the first COPY command.

Thank You.
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#148518 - 05/09/27 01:39 AM Re: Script Check Please: Use of FOR EACH
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 01/06/05
Posts: 22294
Loc: Claremore, OK
ja, it's not.
you each for each needs corresponding next, just like if needs endif.
that is, you can't have more "next" than you have "for each"
_________________________
!

download KiXnet

Top
#148519 - 05/09/27 01:58 AM Re: Script Check Please: Use of FOR EACH
NTDOC Administrator Offline
Administrator
*****

Registered: 00/07/28
Posts: 11547
Loc: CA
Quote:


For Each
 
Action: Repeats a group of statements for each element in an array or collection.
 
Syntax: FOR EACH $element IN group
   statements…
NEXT
 
Parameters: Element
 
Variable used to iterate through the elements of the collection or array.
 
Group
 
Name of an object collection or array.
 
Remarks: FOR EACH loops can be nested as many times as memory allows.
 
The For Each block is entered if there is at least one element in group. Once the loop has been entered, all the statements in the loop are executed for the first element in group. As long as there are more elements in group, the statements in the loop continue to execute for each element. When there are no more elements in group, the loop is exited and execution continues with the statement following the Next statement.
 
See Also: Do Until, For Next, While Loop
 
Examples: Dim $MyArray[10]
For Each $Element In $MyArray
 ? $Element
Next
 
$Root = GetObject( "LDAP://localhost" )
For Each $Obj in $Root
  ? $Obj.name
Next




Top
#148520 - 05/09/27 02:05 AM Re: Script Check Please: Use of FOR EACH
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 05/06/15
Posts: 506
Loc: Oregon, USA
Thank you both for your comments. Both posts helped contribute to my understanding.

Please review my revised code (including registry values from another post on registry keys)

Code:
 

$sourceDir = 'V:\hotfixes\CAD to RMS fix files\'
$destDir1 = 'C:\Program Files\Common Files\Borland Shared\BDE\'
$destDir2 = '%windir%\system32\'
$checkFile = 'DONOTDELETE-CADFix1.txt'
$sourceFiles1 = 'sql_mss','sqllnk32.cnt','sqllnk32.fts','sqllnk32.hlp','SQLLNK32.TOC','sqlmss32.dll'
$sourceFiles2 = 'ntwdblib.dll'
$Key1 = "HKLM\SOFTWARE\Borland\Database Engine\Settings\DRIVERS\MSSQL"

IF left(@wksta,2) = "PD"
$Result = EXIST($destdir2 + $checkFile)
IF $Result = 0
for each $File1 in $sourceFiles1
copy $sourceDir + $File1 $destDir1 + $File1
next
copy $sourceDir + $sourceFiles2 $destDir2 + $sourceFiles2
copy $sourceDir + $checkFile $destDir2 + $checkFile
$rc = WriteValue ($key1 + "\DB OPEN","DATABASE NAME","","REG_SZ")
$rc = WriteValue ($key1 + "\DB OPEN","SERVER NAME","MSS_SERVER","REG_SZ")
$rc = WriteValue ($key1 + "\DB OPEN","USER NAME","MYNAME","REG_SZ")
$rc = WriteValue ($key1 + "\DB OPEN","OPEN MODE","READ/WRITE","REG_SZ")
$rc = WriteValue ($key1 + "\DB OPEN","SCHEMA CACHE SIZE","8","REG_SZ")
$rc = WriteValue ($key1 + "\DB OPEN","BLOB EDIT LOGGING","","REG_SZ")
$rc = WriteValue ($key1 + "\DB OPEN","LANGDRIVER","","REG_SZ")
$rc = WriteValue ($key1 + "\DB OPEN","SQLQRYMODE","","REG_SZ")
$rc = WriteValue ($key1 + "\DB OPEN","SQLPASSTHRU MODE","SHARED AUTOCOMMIT","REG_SZ")
$rc = WriteValue ($key1 + "\DB OPEN","DATE MODE","0","REG_SZ")
$rc = WriteValue ($key1 + "\DB OPEN","SCHEMA CACHE TIME","-1","REG_SZ")
$rc = WriteValue ($key1 + "\DB OPEN","MAX QUERY TIME","300","REG_SZ")
$rc = WriteValue ($key1 + "\DB OPEN","MAX ROWS","-1","REG_SZ")
$rc = WriteValue ($key1 + "\DB OPEN","BATCH COUNT","200","REG_SZ")
$rc = WriteValue ($key1 + "\DB OPEN","ENABLE SCHEMA CACHE","FALSE","REG_SZ")
$rc = WriteValue ($key1 + "\DB OPEN","SCHEMA CACHE DIR","","REG_SZ")
$rc = WriteValue ($key1 + "\DB OPEN","HOST NAME","","REG_SZ")
$rc = WriteValue ($key1 + "\DB OPEN","APPLICATION NAME","","REG_SZ")
$rc = WriteValue ($key1 + "\DB OPEN","NATIONAL LANG NAME","","REG_SZ")
$rc = WriteValue ($key1 + "\DB OPEN","ENABLE BCD","FALSE","REG_SZ")
$rc = WriteValue ($key1 + "\DB OPEN","TDS PACKET SIZE","4096","REG_SZ")
$rc = WriteValue ($key1 + "\DB OPEN","BLOB TO CACHE","64","REG_SZ")
$rc = WriteValue ($key1 + "\DB OPEN","BLOB SIZE","32","REG_SZ")
$rc = WriteValue ($key1 + "\INIT","VERSION","4.0","REG_SZ")
$rc = WriteValue ($key1 + "\INIT","TYPE","SERVER","REG_SZ")
$rc = WriteValue ($key1 + "\INIT","DLL32","SQLMSS32.DLL","REG_SZ")
$rc = WriteValue ($key1 + "\INIT","VENDOR","INIT","REG_SZ")
$rc = WriteValue ($key1 + "\INIT","CONNECT TIMEOUT","60","REG_SZ")
$rc = WriteValue ($key1 + "\INIT","TIMEOUT","300","REG_SZ")
$rc = WriteValue ($key1 + "\INIT","DRIVER FLAGS","","REG_SZ")
$rc = WriteValue ($key1 + "\INIT","TRACE MODE","0","REG_SZ")
$rc = WriteValue ($key1 + "\INIT","MAX DBPROCESSES","31","REG_SZ")
ENDIF
ENDIF



Edited by StarwarsKid (05/09/27 09:19 PM)
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Chris S., Glenn Barnas, ShaneEP, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (green78) and 144 anonymous users online.
Newest Members
Keris2112, Jorromans, qrstuv140696, Bloodboy, NIJAKIX
17451 Registered Users

Generated in 0.059 seconds in which 0.026 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