Jump to content
Sign in to follow this  

Array question

Recommended Posts


Hi All,

I have a directory that will continually get populated with PDF files.  Any files that over 24 hours will automatically be deleted.

The file name will be in this type of format:  "zzztest,  ann_01122017065226.pdf"

I'm not concerned with who's name is in the file name, what I am trying to do is pull the ending date and

time, out of the file name. Which I have done successfully.  When my program gets to the part where I want to dissect the

date and flip it to yyyy/mm/dd format, the string I send IsArray() does not work.  Here is the code snippet:


        $sFileName = String(FileFindNextFile($hFile))
        $sNewFile = StringTrimRight($sFileName, 4)
        $sFileName = StringRight($sNewFile, 14)
        $aTime = StringRight($sFileName, 6)
        $aDate = StringTrimRight($sFilename, 6)
        $aDate = '"' & $aDate & '"'
        MsgBox(0, "", $aDate, 2)
        If IsArray($aDate) Then
            $iMon  = Number($aDate[3]); [0] for Year when $aFDate
            MsgBox(0, "", $iMon,2)
            $iDay  = Number($aDate[4]); [1] for Month when $aFDate 
            MsgBox(0, "", $iDay,2)
            $iYear = Number($aDate[5]); [2] for Day when $aFDate
            MsgBox(0, "", $iYear,2)        
            Msgbox(0, "", "Not an array", 2)


As you can see I tried adding in quotes.  Is there something else I need to do with this file name to get IsArray to recognize it as an






Edited by JLogan3o13

Share this post

Link to post
Share on other sites

Not sure why everyone posts in Developer forum first time; moved to General Help and Support.

@jmj4331 welcome to the forum. Please use code tags <> when you post code, makes it much easier to read. I have done so for you in your initial post.


√-1 2^3 ∑ π, and it was delicious!

Share this post

Link to post
Share on other sites

Melba's Date_Time_Convert UDF should be able to do the conversion for you:

That way you don't have to mess around with it yourself.


Share this post

Link to post
Share on other sites

If $aDate displays in a Msgbox, then it is a string, not an array. BTW the correct naming (prefix) should be here $sDate

But you don't need to go the array way. There is a nice example in the helpfile for the func StringRegExpReplace
Using this example, to fit your needs this could be done

$sFileName = "zzztest,  ann_01122017065226.pdf" 

$sDate = StringRegExpReplace($sFileName, '.*(\d{2})(\d{2})(\d{4})\d{6}.pdf', "$3/$2/$1")
Msgbox(0, "", $sDate)


Share this post

Link to post
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
Sign in to follow this