List() problems and fileExists() solution.

Giganews Newsgroups
Subject: List() problems and fileExists() solution.
Posted by:  David Goadby (dav…@dgoadby.demon.co.uk)
Date: Sun, 8 Aug 2004

In order to test if a file exists on an FTP site in the current directory I
did the following List(FileList, 'testfilename', False). The plan was to
test the Count of the entries in FileList to see if a file existed or not.
The result is that if the file exists then it works. If the file does not
exist then I get an exception:
    EIdProtocolReplyError with Message:" testfilename: No such file or
directory"  - not what I expected.
Then I changed the detail parameter to True and it does work.

This led me to explore the functionality of List. The test was carried on a
Linux hosted site with current directory = site_root ('.') and there were
files at top level and non-empty subdirectories. The FileList was copied to
a Memo component to see the results. This is what I found:

List(FileList,'*',True) produces four basic lists:
    all files in current directory
    all files and directories at current level with .: as the first entry
    all files and directories at current level with ..: as the first entry
    all directories and their files listed by directory (each directory is a
list)

List(FileList,'*',False) produces one list:
    all files from current level and all directories. In effect a complete
tree with no . or .. entries

List(FileList,'*.',True) produces two lists:
    all files in current directory with .: as the first entry
    all files in current directory with ..: as the first entry

List(FileList,'*.',False) produces an Exception: EIdProtocolReplyError -
Message "No Files Found"

List(FileList,'*.*', True) produces three lists
    all files in current directory
    all files in current directory with .: as the first entry
    all files in current directory with ..: as the first entry

List(FileList,'*.*', False) produces one list
    all files in current directory only (no . or ..)

I am confused by the inconsistency of the results with detail True/False as
I expected the lists to be the same except with, or without, the detail.

I haven't had time to research further but at least I have been able to make
my FileExists(testfilename) function work by using :
...
List(FileList, testfilename, True);
if FileList.Count > 0 then
    FileExists := True //  more than 1 should never happen
else
    FileExists := False;
...

--
Regards

David Goadby

Replies