GETLIST Get the file or directory list of the current local or remote directory
Syntax:
GETLIST(variable_name,list_type,filter)
- variable_name: GETLIST will save the list in this variable. Usually, this variable is used in the FOREACH loop.
- list_type:
LOCAL_FILES Local file list LOCAL_DIRECTORIES Local directory list REMOTE_FILES Remote file list REMOTE_DIRECTORIES Remote directory list - wildcard (optional): if this parameter is used GETLIST will only include in the resulting list the files or directories that match this wildcard. For example “*.txt” will make GETLIST create a list of text files only.
Remarks:
- The resulting list can be used in the FOREACH loop. This way you can make ScriptFTP do a different set of actions for each file in the list.
- Every ScriptFTP variable contains a text string and the list that this command creates is not an exception. The character “|” is used to separate the items of the list. Therefore, you can also build file lists without GETLIST. For example: $mylist=”a.txt|b.txt|c.txt”.
Return value:
This command will return “OK” if no error was found retrieving the file list.
Command history:
This command was added in ScriptFTP 3.0 build July 28th 2008
See also:
Examples:
# Connect to server OPENHOST("ftp.myhost.com","joe","123456") # Change the current local directory. All files # will be downloaded here. LOCALCHDIR("C:\users\carlos\desktop\localftp") # Get the remote file listing, store it in $list GETLIST($list,REMOTE_FILES,"*.txt") # For each file in $list... FOREACH $item IN $list # Download the file $result=GETFILE($item) # If the file has been downloaded successfully # delete the remote copy, else stop the script. IF($result=="OK") DELETEFILE($item) ELSE STOP END IF END FOREACH # Close the connection CLOSEHOST
# Connect to server OPENHOST("127.0.0.1","carl","123456") # Get the remote directory listing, store it in $list GETLIST($list,REMOTE_DIRECTORIES) # For each directory in $list print the name FOREACH $item IN $list PRINT($item) END FOREACH # Get the local directory listing, store it in $list GETLIST($list,LOCAL_DIRECTORIES) # For each directory in $list print the name FOREACH $item IN $list PRINT($item) END FOREACH # Close the connection CLOSEHOST