I'm getting somewhere now and have got my loops in place, so just need by Brand (--b:) input validation to get sorted out. the below is my current code
 Code:
break on
call @ScriptDir + "\dirlist.udf"
call @ScriptDir + "\dirplus.udf"
call @ScriptDir + "\msg.udf"
call @ScriptDir + "\copyfiles.udf"
call @ScriptDir + "\readexcel2.udf"

$Brandshop = readexcel2(@Scriptdir + '\pccs.xlsx',,-1,-1)

If @ERROR = "2"                    ; pcc spreadsheet is required - die if not provided
  ? 'ERROR OCCURED: @serror (@error)' @CRLF @CRLF
  Quit 1
EndIf

; Get the source, dest & brand args specified on the command-line

; get the command line as an array - elements 0 & 1 are the kix.exe and the script.kix items
$aCmdLine = GetCommandLine(1)

; scan the array looking for the source arg
$ = AScan($aCmdLine, '--s:', , , 1)        ; get SOURCE arg
If $ > 1                    ; 
  $Source = SubStr($aCmdLine[$], 5)
Else                        ; arg is required - die if not provided
  'ERROR: Source was not specified!' @CRLF @CRLF
  'Usage: myscript.kix --s:Source_path --d:destination_path --b:brand' @CRLF
  Quit 1
EndIf

; scan the array looking for the destination arg
$ = AScan($aCmdLine, '--d:', , , 1)        ; get destination arg
If $ > 1                    ; 
  $Dest = SubStr($aCmdLine[$], 5)
Else                        ; arg is required - die if not provided
  'ERROR: Destination was not specified!' @CRLF @CRLF
  'Usage: myscript.kix --s:Source_path --d:destination_path --b:brand' @CRLF
  Quit 1
EndIf

; scan the array looking for the brand arg
$ = AScan($aCmdLine, '--b:', , , 1)        ; get brand type
If $ > 1                    ; 
  $Brand = SubStr($aCmdLine[$], 5)
Else                        ; arg is required - die if not provided
  'ERROR: Brand was not specified or was invalid!' @CRLF @CRLF
  'Usage: myscript.kix --s:Source_path --d:destination_path --b:brand' @CRLF
  Quit 1
EndIf

$destdirs = Dir($dest + "\*")

While $destdirs <> "" and @Error = 0
    For $rowcount = 0 to ubound($Brandshop)
        Select
            Case $Brand = $Brandshop[$rowcount,1] and $destdirs = $Brandshop[$rowcount,0]
                $copycentral = CopyFiles($Source,$Dest + "\" + $destdirs,0,1)
            Case $Brand = "ALL" and $destdirs = $Brandshop[$rowcount,0]
                $copycentral = CopyFiles($Source,$Dest + "\" + $destdirs,0,1)
            Case 1
        EndSelect
    Next
    $destdirs = Dir()
Loop
exit


The last thing here is to get in some input validation. I know that readexcel2() reads into an array. Should I verify the Brand input directly against the array as built, or is it better to build another array of unique elements?

My only problem is that the Brand for some branches is intentionally left blank and so I don't know what effect this might have. If I build an array of unique elements, then I can use that in the array in the error feedback to the script runner.

Anyone wondering about logging failures and successes, then I'll sort that out writing to a file which will then launch Excel when copy is finished and view results/errors/error codes, etc.

Pax

edit: oooo just found qsort() and uniq(). I will explore tomorrow.


Edited by Pax (2010-10-05 06:42 PM)
Edit Reason: research