Jump to content

Sequential File Url UDF


AvaCompute
 Share

Recommended Posts

Convert single URL to sequential file URL

#include-once
;—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
;
;   Title ………………………… : Convert single URL to sequential file URL
;   Author(s) ……………… : AvaCompute
;   AutoIt Version … : 3.3.12.0
;
;   URL Sample:
;               http://www.host.com/file54.rar
;
;   URL Result:
;               http://www.host.com/file01.rar
;               http://www.host.com/file02.rar
;               http://www.host.com/file03.rar
;               ...
;               http://www.host.com/file54.rar
;
Func GetSequentialFileUrl( $Url , $ZeroFill = True , $StartFileIndex = 1 )
    ;…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………
    Local $AllFileUrl
    Local $LastFileNumber
    Local $UrlStringFormat
    Local $CharNumberPrefix
    Local $sDigit = 0 , $eDigit = 0
    Local Const $EscapeCharacter = '%'
    Local Const $UrlDelimitersChar = '\'
    ;…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………
    $Url = StringReplace( $Url , $EscapeCharacter , $EscapeCharacter & $EscapeCharacter )
    ;…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………
    For $pChar = StringLen( $Url ) To 1 Step -1
        If ( StringIsDigit( StringMid( $Url , $pChar , 1 ))) Then
            $eDigit = $pChar
            ExitLoop
        EndIf
    Next
    ;…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………
    If ( $eDigit == 0 ) Then
        Return SetError( -1 )
    EndIf
    ;…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………
    For $pChar = $eDigit To 1 Step -1
        If ( Not StringIsDigit( StringMid( $Url , $pChar , 1 ))) Then
            $sDigit = $pChar + 1
            ExitLoop
        EndIf
    Next
    ;…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………
    If ( $sDigit == 0 ) Then
        Return SetError( -2 )
    EndIf
    ;…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………
    $LastFileNumber = Number( StringMid( $Url , $sDigit , ( $eDigit - $sDigit ) + 1 ) , 1 )
    ;…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………
    If ( $ZeroFill ) Then
        $CharNumberPrefix = '%0' & StringLen( String( $LastFileNumber )) & 'd'
    Else
        $CharNumberPrefix = '%d'
    EndIf
    ;…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………
    $UrlStringFormat = StringLeft( $Url , $sDigit - 1 ) & $CharNumberPrefix & StringRight( $Url , StringLen( $Url ) - $eDigit )
    ;…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………
    If ( $StartFileIndex > $LastFileNumber ) Then
        Return SetError( -3 )
    EndIf
    ;…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………
    For $iFile = $StartFileIndex To $LastFileNumber
        $AllFileUrl &= StringFormat( $UrlStringFormat , $iFile ) & $UrlDelimitersChar
    Next
    ;…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………
    $AllFileUrl = StringTrimRight( $AllFileUrl , StringLen( $UrlDelimitersChar ))
    ;…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………
    Return StringSplit( $AllFileUrl , $UrlDelimitersChar )
    ;…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………
EndFunc
;—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
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
 Share

  • Recently Browsing   0 members

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