kylomas Posted August 18, 2013 Share Posted August 18, 2013 drbyte, i need to know on which position in the array the value for material-1a or material-1b and so on is, so that i always take the correct value to place int the excell sheet. The position of the file within the array is dependent on what _FileListToArray returns. You can search for any file by name (such as you've done or using _arraysearch UDF). kylomas drbyte 1 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Solution soonyee91 Posted August 18, 2013 Solution Share Posted August 18, 2013 (edited) I think i solved it with the code below. (only for looking up 1a) For $1 = 0 To UBound($aFiles) - 1 If StringInStr($aFiles[$1][0], '-1a') > 0 Then ConsoleWrite('Found "1a" in element ' & $1 & ' of array' & @LF) EndIf Next Is there a smart way to search from 1a to 1f ? Try this method: For $1 = 0 To UBound($aFiles) - 1 Select Case StringInStr($aFiles[$1][0], '-1a') > 0 ConsoleWrite('Found '&$aFiles[$1][0]&' in element ' & $1 & ' of array' & @LF) Case StringInStr($aFiles[$1][0], '-1b') > 0 ConsoleWrite('Found '&$aFiles[$1][0]&' in element ' & $1 & ' of array' & @LF) Case StringInStr($aFiles[$1][0], '-1c') > 0 ConsoleWrite('Found '&$aFiles[$1][0]&' in element ' & $1 & ' of array' & @LF) Case StringInStr($aFiles[$1][0], '-1d') > 0 ConsoleWrite('Found '&$aFiles[$1][0]&' in element ' & $1 & ' of array' & @LF) Case StringInStr($aFiles[$1][0], '-1e') > 0 ConsoleWrite('Found '&$aFiles[$1][0]&' in element ' & $1 & ' of array' & @LF) Case StringInStr($aFiles[$1][0], '-1f') > 0 ConsoleWrite('Found '&$aFiles[$1][0]&' in element ' & $1 & ' of array' & @LF) EndSelect Next Or you can try this simplified version using _ArrayFindAll() local $criteria, $array,$count, $write For $count=0 to 5 ; loop from a to f $array=_ArrayFindAll($aFiles,"-1"&stringlower(Chr(65 + $count)),0,0,1,1,0) ; use this function to retrieve the index similar criteria in array form For $write=0 to Ubound($array)-1 ; write to the console fo each of them ConsoleWrite('Found '& $aFiles[$array[$write]][0] &' in element ' & $array[$write] & ' of array' & @LF) Next Next ; Above function will be more simpler than using select, case method Both function will produce the same outcome. Edited August 18, 2013 by soonyee91 drbyte 1 Link to comment Share on other sites More sharing options...
junkew Posted August 18, 2013 Share Posted August 18, 2013 (edited) This solution takes a different approach and will also with wildcards using fileexists and puts a 1 in the array if the file exists. Array to excel should be easy as file position is allways the same exact match if you uncomment the code of the first array (and comment out current array) Edit: Made it in the example all with wildcard * expandcollapse popuplocal $i ;~ local $myFiles[2][8] = [ _ ;~ ["material-1a_124567.pdf", _ ;~ "material-1b_12345_12345.pdf" , _ ;~ "material-1c_12345_nesting.pdf", _ ;~ "material-1d_us_04030-2010-09-03.pdf", _ ;~ "material-1e_z35_SL1020_01.pdf", _ ;~ "material-1f_W1305050.pdf", _ ;~ "material-1g_SL1025_02.pdf", _ ;~ "material-1h_painting.pdf"], _ ;~ [0,0,0,0,0,0,0,0]] local $myFiles[2][8] = [ _ ["material-1a*.pdf", _ "material-1b*.pdf" , _ "material-1c*.pdf", _ "material-1d*.pdf", _ "material-1e*.pdf", _ "material-1f*.pdf", _ "material-1g*.pdf", _ "material-1h*.pdf"], _ [0,0,0,0,0,0,0,0]] local $checkInFolder=@ScriptDir consolewrite("Start looking for files " & @CRLF) for $i=0 to ubound($myFiles,2)-1 consolewrite($i & @TAB & $checkInFolder & "\" & stringformat("[%-35s]",$myFiles[0][$i]) & @TAB & $myFiles[1][$i] & @CRLF) if fileexists($checkInFolder & "\" & $myFiles[0][$i]) Then $myFiles[1][$i]=1 endIf Next consolewrite("Those files with a 1 behind exists" & @CRLF) for $i=0 to ubound($myFiles,2)-1 consolewrite($i & @TAB & stringformat("[%-35s]",$myFiles[0][$i]) & @TAB & $myFiles[1][$i] & @CRLF) Next consolewrite("End " & @CRLF) Edited August 18, 2013 by junkew drbyte 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
drbyte Posted August 18, 2013 Author Share Posted August 18, 2013 (edited) soonyee91 Both your solutions work like a charm! Now i can go on and manipulate some of the values, so for me the "case select" method will be the best to use i believe. Global $Certificate Global $Chargenr For $1 = 0 To UBound($aFiles) - 1 Select Case StringInStr($aFiles[$1][0], 'material-1a') > 0 ConsoleWrite('Found ' & $aFiles[$1][0] & ' in element ' & $1 & ' of array' & @LF) Case StringInStr($aFiles[$1][0], 'material-1b') > 0 ConsoleWrite('Found "1b" in element ' & $1 & ' of array' & @LF) $Certificate = $aFiles[$1][1] Local $array5 = StringSplit($Certificate, "_", 1) $Certificate = $array5[1] $Chargenr = $array5[2] Case StringInStr($aFiles[$1][0], 'material-1c') > 0 ConsoleWrite('Found ' & $aFiles[$1][0] & ' in element ' & $1 & ' of array' & @LF) Case StringInStr($aFiles[$1][0], 'material-1d') > 0 ConsoleWrite('Found ' & $aFiles[$1][0] & ' in element ' & $1 & ' of array' & @LF) Case StringInStr($aFiles[$1][0], 'material-1e') > 0 ConsoleWrite('Found ' & $aFiles[$1][0] & ' in element ' & $1 & ' of array' & @LF) Case StringInStr($aFiles[$1][0], 'material-1f') > 0 ConsoleWrite('Found ' & $aFiles[$1][0] & ' in element ' & $1 & ' of array' & @LF) EndSelect Next Edited August 18, 2013 by drbyte Link to comment Share on other sites More sharing options...
junkew Posted August 18, 2013 Share Posted August 18, 2013 smart searching. You can make use of the fact that you seem to be having a-f after the 1. The ascii values of a-f are just sequential so subtract 96 (or 97 if you prefer to start with 0) local $checkInFolder=@ScriptDir ; Shows the filenames of all files in the current directory. Local $search = FileFindFirstFile($checkinfolder & "\material*.*") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 Local $file = FileFindNextFile($search) If @error Then ExitLoop consolewrite("File : " & stringformat("[%-35s]",$file) & " is at position: " & asc(StringMid($file,11,1)) -96 & @CRLF) WEnd ; Close the search handle FileClose($search) drbyte 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
drbyte Posted August 18, 2013 Author Share Posted August 18, 2013 junkew This is what i mean by "smart searching" !! Thnx Link to comment Share on other sites More sharing options...
soonyee91 Posted August 19, 2013 Share Posted August 19, 2013 drbyte, Its good to know you can understand both solution. Personally I would prefer 2nd solution because of shorter structure. XD Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now