MikeK6MKF Posted March 8, 2015 Posted March 8, 2015 (edited) I want to research how to do this in AutoIt, but I really don't know where to begin. I am running an AutoIt script from a directory in which I have a number of PDF files. These files are: K6MKF-MAR-2015-_01-Mar-2015_14-55-47_UTC_10.pdf K6MKF-MAR-2015-_01-Mar-2015_14-55-47_UTC_12.pdf K6MKF-MAR-2015-_01-Mar-2015_14-55-47_UTC_15.pdf K6MKF-MAR-2015-_01-Mar-2015_14-55-47_UTC_17.pdf K6MKF-MAR-2015-_01-Mar-2015_14-55-47_UTC_20.pdf K6MKF-MAR-2015-_01-Mar-2015_14-55-47_UTC_30.pdf K6MKF-MAR-2015-_01-Mar-2015_14-55-47_UTC_40.pdf K6MKF-MAR-2015-_01-Mar-2015_14-55-47_UTC_80.pdf At present, my script is only able to access files that I have renamed UTC_10.pdf ... UTC_80.pdf because I don't know enough AutoIt to be able to access the files individually using some construct such as *UTC_80.pdf. Other users' files will certainly have different file names, and these are generated by another system and each filename ends with UTC_10.pdf ... UTC_80.pdf. I use the filename string of 'UTC_10.pdf' as part of a Run statement to view specific pages of specific files. So I need to find a way to write the Run statement so that it will resolve the full filename when all the script knows is the last 10 characters: UTC_10.pdf ... UTC_80.pdf. ; ; ; Local $AcrobatPath = '"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" /A page=' Local $PDFDirm = @ScriptDir Local $PDFDir $PDFDir = (" " & $PDFDirm) ... $utc = _GetUTC() $page = StringFormat("%02d", (($utc + 100) / 100 )) $strTest = ($AcrobatPath & $page & $PDFDir & '\UTC_80.pdf') Run($strTest) ; Probably pretty much a kludge, but the best I can do at this point ; ; Any guidance, advice and suggestions will be greatly appreciated. Thank you. Edited March 8, 2015 by MikeK6MKF
markyrocks Posted March 8, 2015 Posted March 8, 2015 (edited) #include <File.au3> $list=_FileListToArray ( @scriptdir ) for $x=1 to ubound($list)-1 $trim[$x-1]=stringtrimright($list[$x],10) next ;compare $data[3]= ["123456.udf","234567.udf","345678.udf","456789.udf"] for $y=0 to ubound($data)-1 for $x=0 to ubound($trim)-1 if $data[$y]=$trim[$x] then ;what to do here shellexecute(@scriptdir & "/" & $list[$x+1]) endif next next ;something like that i'm sure there may be easier methods but that would be my attempt to brute force it...edit:added second array I'd say use something like _filelistoarray(). Once the is is in an array run it through stringtrimright () then compare the string to the info you have available and determine if the file meets the criteria. Edit fixed my rookie mistake Edited March 8, 2015 by markyrocks Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning"
TheSaint Posted March 8, 2015 Posted March 8, 2015 I'm guessing you could try using the asterisk wild card, twice. *_UTC_*.pdf Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)
MikeK6MKF Posted March 8, 2015 Author Posted March 8, 2015 My thanks to you both for your suggestions. I will try both solutions and let you know my results. Learning a lot about AutoIt every day!
markyrocks Posted March 8, 2015 Posted March 8, 2015 Apparently $file [0] is the number of files in the array.... so let me adjust the above code Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning"
Solution MikeK6MKF Posted March 9, 2015 Author Solution Posted March 9, 2015 My sincere thanks to all who replied with suggestions. Thanks to you, I have this part of the code working. Global $UTCTime, $band, $foundfilename ... Func mapBandToFile($band) ; Look for band in the array of files and return the index to that file ; returns -1 if no file found for the band Local $bandsub, $foundfile For $i=1 to Ubound($filelist) - 1 $foundfile = StringInStr($fileList[$i], "UTC_" & $band) If $foundfile <> 0 Then ExitLoop EndIf Next If $i <> UBound($fileList) Then ; We found the required file ; set $foundfilename with leading backslash $foundfilename = ("\" & $fileList[$i]) Else ; We didn’t find the file Return -1 EndIf EndFunc ;===> mapBandToFile Now the script runs as I have imagined it. I must now stop coding and do all the AutoIT tutorials so I can learn what it is I've done!
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