Jump to content

Resolving a full Windows filename from a fixed partial filename string

Go to solution Solved by MikeK6MKF,

Recommended Posts

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:
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')

; 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 by MikeK6MKF
Link to comment
Share on other sites

#include <File.au3>
$list=_FileListToArray ( @scriptdir )

for $x=1 to ubound($list)-1


$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])
;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 by markyrocks
Link to comment
Share on other sites

I'm guessing you could try using the asterisk wild card, twice.


Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.


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)


Link to comment
Share on other sites

  • Solution

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
    If $i <> UBound($fileList) Then
        ; We found the required file
        ; set $foundfilename with leading backslash
    $foundfilename = ("\" & $fileList[$i])
        ; We didn’t find the file
        Return -1
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!   :geek:

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...