Marcelos

Enumerate files from http directory listing

1 post in this topic

#1 ·  Posted (edited)

Hi

wanted to share this solution since I count find by goggling it

the idea is to access an http folder and enumerate the files

Hope it helps

#include <Array.au3>

$RepoProjectDB="http://acnalert.cloudapp.net/FGM/ProjectRepo"

Local $sData = InetRead($RepoProjectDB)
Local $nBytesRead = @extended
local $files[1]
$rawData=BinaryToString($sData)

;filter the fwanted iles
$LinesArr=StringRegExp($rawData,">.*\.db</a>",3)

for $i=0 to UBound($LinesArr)-1
    $startFileName=StringInStr($LinesArr[$i],'href="')+6
    $endFileName=StringInStr($LinesArr[$i],'">',0,1,$startFileName)
    $fileName=StringMid($LinesArr[$i],$startFileName,$endFileName-$startFileName)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $fileName = ' & $fileName & @crlf )
    $files[$i]=$fileName
    redim $files[$i+2]
next
_ArrayDelete($files,UBound($files)-1)

ConsoleWrite( "Total Bytes read: "& $nBytesRead & @CRLF & @CRLF & BinaryToString($sData))
_printfromarray($LinesArr)
_printfromarray($files)



; #FUNCTION# ====================================================================================================================
; Name ..........: _PrintFromArray
; Description ...: Print an array to the console.
; Syntax ........: _PrintFromArray(Const Byref $aArray[, $iBase = Default[, $iUBound = Default[, $sDelimeter = "|"]]])
; Parameters ....: $aArray              - [in/out and const] The array to be written to the file.
;                  $iBase               - [optional] Start array index to read, normally set to 0 or 1. Default is 0.
;                  $iUBound             - [optional] Set to the last record you want to write to the File. Default is whole array.
;                  $sDelimeter          - [optional] Delimiter character(s) for 2-dimension arrays. Default is "|".
; Return values .: Success - 1
;                  Failure - 0 and sets @error to non-zero
;                   |@error:
;                   |1 - Input is not an array.
;                   |2 - Array dimension is greater than 2.
;                   |3 - Start index is greater than the size of the array.
; Author ........: guinness
; Modified ......:
; Remarks .......:
; Related .......: _FileWriteFromArray
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================

    Func _PrintFromArray(ByRef Const $aArray, $iBase = Default, $iUBound = Default, $sDelimeter = "|")
        ; Check if we have a valid array as input
        If Not IsArray($aArray) Then Return SetError(1, 0, 0)

        ; Check the number of dimensions
        Local $iDims = UBound($aArray, 0)
        If $iDims > 2 Then Return SetError(2, 0, 0)

        ; Determine last entry of the array
        Local $iLast = UBound($aArray) - 1
        If $iUBound = Default Or $iUBound > $iLast Then $iUBound = $iLast
        If $iBase < 0 Or $iBase = Default Then $iBase = 0
        If $iBase > $iUBound Then Return SetError(3, 0, 0)

        If $sDelimeter = Default Then $sDelimeter = "|"

        ; Write array data to the console
        ConsoleWrite("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & @CRLF)
        Switch $iDims
            Case 1
                For $i = $iBase To $iUBound
                    ConsoleWrite("[" & $i - $iBase & "] " & $aArray[$i] & @CRLF)
                Next
            Case 2
                Local $sTemp = ""
                Local $iCols = UBound($aArray, 2)
                For $i = $iBase To $iUBound
                    $sTemp = $aArray[$i][0]
                    For $j = 1 To $iCols - 1
                        $sTemp &= $sDelimeter & $aArray[$i][$j]
                    Next
                    ConsoleWrite("[" & $i - $iBase & "] " & $sTemp & @CRLF)
                Next
            EndSwitch
            ConsoleWrite("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & @CRLF)
        Return 1
    EndFunc   ;==>_PrintFromArray

 

Edited by Marcelos

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