Jump to content
Sign in to follow this  

_Ftp_ListToArray with filter!

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]
    If Not $sFileList Then Return SetError(4, 4, "")
    Return StringSplit(StringTrimLeft($sFileList, 1), "|")
EndFunc   ;==>_FTP_ListToArrayPlus

I hope you like


Edited by golfinhu

Share this post

Link to post
Share on other sites

Maybe not useful for everyone? If i have to filter files from ftp I can add checking their names to working While...WEnd

Edited by theghost

Share this post

Link to post
Share on other sites

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

Share this post

Link to post
Share on other sites

ehi golfinhu, it is fantastic!

do you know how can I do for filter more extensions?

thank you! ;-)

ehi ehi ehi, what is your name?

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.