Jump to content

_Ftp_ListToArray with filter!


golfinhu
 Share

Recommended Posts

this is my function it lists the files on the server and can be used extension filter!

p.s: you need include the FtpEX.au3 to work!

; #FUNCTION# ====================================================================================================================
; Name...........: _FTP_ListToArrayPlus
; Description ...: Get Filenames, Directories or Both of current remote directory with the possibility of using extension filters.
; Syntax.........: _FTP_ListToArrayPlus($FTPconnectionhandle[, $sFilter = "*", $Return_type = 0]])
; Parameters ....: $l_FTPSession  - as returned by _FTP_Connect().
;                  $sFilter   - Optional, Name or extension of files, example: (index.htm; *.html)
;                  $Return_type   - Optional, 0 = Both Files and Directories, 1 = Directories, 2 = Files.
; Return values .: Success      - An array containing the names. Array[0] contain the number of found entries.
;                  Failure      - Return @error
; Author ........: Golfinhu
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _FTP_ListToArrayPlus($FTPconnectionhandle, $sFilter = "*", $Return_type = 0)
    Local $hSearch, $sFile, $sFileList, $h_Handle, $sPath = _FTP_DirGetCurrent($FTPconnectionhandle), $sDelim = "|"
    $sPath = StringRegExpReplace($sPath, "[\\/]+\z", "") & "/"
    If StringRegExp($sFilter, "[\\/:><\|]|(?s)\A\s*\z") Then Return SetError(1, 1, "")
    If Not ($Return_type = 0 Or $Return_type = 1 Or $Return_type = 2) Then Return SetError(2, 2, "")
    $hSearch = _FTP_FindFileFirst($FTPconnectionhandle, $sPath & $sFilter, $h_Handle, $INTERNET_FLAG_RESYNCHRONIZE)
    If @error Then Return SetError(3, 3, "")
    If Not ($Return_type = 1 And $hSearch[1] = 16) And Not ($Return_type = 2 And $hSearch[1] <> 16) Then $sFileList &= $sDelim & $hSearch[10]
    While 1
        $sFile = _FTP_FindFileNext($h_Handle)
        If @error Then ExitLoop
        If ($Return_type = 1 And $sFile[1] = 16) Or ($Return_type = 2 And $sFile[1] <> 16) Then ContinueLoop
        $sFileList &= $sDelim & $sFile[10]
    WEnd
    FileClose($hSearch)
    If Not $sFileList Then Return SetError(4, 4, "")
    Return StringSplit(StringTrimLeft($sFileList, 1), "|")
EndFunc   ;==>_FTP_ListToArrayPlus

I hope you like

=)

Edited by golfinhu
Link to comment
Share on other sites

  • 4 weeks later...
  • 1 month later...

FYI: The third parameter of "1" shows FILES and "2" shows DIRECTORIES.

Also, it only works once. If I call the function more than once, it doesn't return anything. The example below displays nothing, but if I comment out the first line, it shows directories in the array.

$arryFil = _Ftp_ListToArrayPlus($Conn,'*',1) ;files
$arryDir = _Ftp_ListToArrayPlus($Conn,'*',2) ;directories
_ArrayDisplay($arryDir)
Link to comment
Share on other sites

  • 4 months later...

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...