tubaguy0 Posted October 15, 2009 Posted October 15, 2009 (edited) Hello, How can I compare each string in an array against a variable? If $LogfileArray[0] <> $FullFilePath AND $FileModifiedDiff <= 2 Then I can get $LogFileArray[1] or [2] and so on to compare 1 on 1 to $FullFilePath, but not the whole array. Thanks for any help. Edited October 15, 2009 by tubaguy0
PsaltyDS Posted October 15, 2009 Posted October 15, 2009 (edited) Hello, How can I compare each string in an array against a variable? If $LogfileArray[0] <> $FullFilePath AND $FileModifiedDiff <= 2 Then I can get $LogFileArray[1] or [2] and so on to compare 1 on 1 to $FullFilePath, but not the whole array. Thanks for any help. You still have to compare each element, but you can do it in an efficient loop: $fMatch = True For $n = 0 To UBound($LogfileArray) - 1 If $LogfileArray[$n] <> $FullFilePath Then $fMatch = False ExitLoop EndIf Next After that runs, $fMatch = True if all elements match $FullFilePath, or False if not. Because of the ExitLoop, it doesn't bother to compare the rest of the array once it finds a mis-match. So the remaining part is just: If $fMatch AND ($FileModifiedDiff <= 2) Then Edited October 15, 2009 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
tubaguy0 Posted October 15, 2009 Author Posted October 15, 2009 (edited) Thanks so much. I inserted your code, and tried it a few ways, but it's not behaving as expected, and I'm sure it's my fault not yours--maybe you can see what I'm missing? $fMatch = True For $n = 0 To UBound($LogfileArray) - 1 If $LogfileArray[$n] <> $FullFilePath Then $fMatch = False ExitLoop EndIf Next If $fMatch AND ($FileModifiedDiff <= 30) Then ; If any selected file has been modified in 30 days or less If StringInStr($FullFilePath, ".pdf", 0) Then ; And is a pdf document FileCopy($FullFilePath, $CopyFolder & $FullPathString, 1) ; Copy it to the CopyFolder CopiedLogFile($FullFilePath) ; Log its file path EndIf EndIf That code should be copying a number of files from one directory to another because their modified date is in the last 30 days *except* for the 6 files that are listed in the log file, which are formatted as $FullFilePath. When I use the code as shown, nothing copies. When I try swapping True and False for your $fMatch variable, all of the files copy. Does that make any sense? Thanks again. Edited October 15, 2009 by tubaguy0
jebus495 Posted October 16, 2009 Posted October 16, 2009 Thanks so much. I inserted your code, and tried it a few ways, but it's not behaving as expected, and I'm sure it's my fault not yours--maybe you can see what I'm missing? $fMatch = True For $n = 0 To UBound($LogfileArray) - 1 If $LogfileArray[$n] <> $FullFilePath Then $fMatch = False ExitLoop EndIf Next If $fMatch AND ($FileModifiedDiff <= 30) Then ; If any selected file has been modified in 30 days or less If StringInStr($FullFilePath, ".pdf", 0) Then ; And is a pdf document FileCopy($FullFilePath, $CopyFolder & $FullPathString, 1) ; Copy it to the CopyFolder CopiedLogFile($FullFilePath) ; Log its file path EndIf EndIf That code should be copying a number of files from one directory to another because their modified date is in the last 30 days *except* for the 6 files that are listed in the log file, which are formatted as $FullFilePath. When I use the code as shown, nothing copies. When I try swapping True and False for your $fMatch variable, all of the files copy. Does that make any sense? Thanks again. For $n = 0 To UBound($LogfileArray) - 1 If $LogfileArray[$n] = $FullFilePath Then If $FileModifiedDiff <= 30 Then FileCopy($FullFilePath, $CopyFolder & $FullPathString, 1) If StringInStr($FullFilePath, ".pdf", 0) Then CopiedLogFile($FullFilePath) EndIf Next Untested. Should copy only files > 30 days old. I think that's what you were after anyway.
tubaguy0 Posted October 16, 2009 Author Posted October 16, 2009 (edited) Thanks for your help PsaltyDS and jebus495... changing the <> to = in PsaltyDS' example resulted in a perfectly working chunk of code that was the last piece of my OCR script. I really, really appreciate the help, that was the last thing I needed to finish my script. Edited October 16, 2009 by tubaguy0
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