golfinhu Posted December 14, 2010 Posted December 14, 2010 (edited) 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 December 14, 2010 by golfinhu
theghost Posted January 6, 2011 Posted January 6, 2011 (edited) Maybe not useful for everyone? If i have to filter files from ftp I can add checking their names to working While...WEnd Edited January 6, 2011 by theghost
wysocki Posted February 10, 2011 Posted February 10, 2011 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)
binarydigit0101 Posted July 7, 2011 Posted July 7, 2011 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?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now