Networking Tools: Thread-hot Internet Classes (int library)
#include <rw/toolpro/dent.h> RWIDirEntry entry("drwxr-xr-x fred staff 512 Apr 24 16:14 pub");
thr, net, int, tls (and possibly std)
The RWIDirEntry is a convenience class that encapsulates parsing and component storage of directory entries typical of those returned from the FTP LIST command. Typically, the directory entry format is some variation of the UNIX ls long format. The RWIDirEntry class is robust in its ability to make sense of the data presented to it. RWIDirEntry expects text similar to the following:
FileType | Owner | Group | Size | Date | Time | Name | Link |
drwxr-xr-x 3 |
fred |
staff |
512 |
Apr 24 |
16:14 |
pub | |
lrwxr-xr-x 1 |
fred |
staff |
512 |
Jan 10 |
1990 |
data |
->/data2 |
-rw-rw-rw- 1 |
fred |
staff |
1024 |
Apr 24 |
12:23 |
stuff |
Often the owner and/or group field is missing. If so, the parsing mechanism provides empty defaults. Datatype checks are performed on the fields (for example, Size must be an integer and Time must be in the form XX:XX). If any field fails its format test, then the object is set to the invalid state and an error text message is saved. This message is available through the error method. If the directory entry parse fails, a copy of the original input string is available through the data method.
#include <iostream.h> #include <rw/cstring.h> #include <rw/toolpro/winsock.h> #include <rw/toolpro/dent.h> void main() { RWWinSockInfo info; RWCString text = "lrwxr-xr-x 1 fred staff 512 Jan 10 1990 data -> /data2" RWIDirEntry de = RWIDirEntry(text); cout << de.name() << endl; cout << de.time() << endl; cout << de.link() << endl; }
Program Output
data 01/10/90 12:00:00 /data2
enum entryType { ftype_directory, ftype_link, ftype_file, ftype_unknown };
Enumerates the possible file types in the file field of an RWIDirEntry object.
The pre-Tools.h++ Professional enum values (DIRECTORY, LINK, FILE, UNKNOWN) have been retained, but are deprecated. You can keep the compiler from seeing the old values by defining RW_AVOID_PREPROCESSOR_PROBLEMS.
RWIDirEntry();
Constructs a default invalid directory entry.
RWIDirEntry(const RWCString& text);
Constructs an RWIDirEntry object from an RWCString.
RWCString data() const;
Returns the raw text that was used to build the object. It is valid to use this method on an object that returns FALSE from the isValid method. It is useful in the event that the entry text could not be parsed successfully.
RWCString error() const;
Returns a text description of the error that was encountered, during the directory entry parsing phase.
RWBoolean isValid() const;
Returns TRUE if the entry was parsed successfully. If it was not, the data method can be used to retrieve the original text, and the error method can be used to return a text description of the parse error.
RWCString link() const;
Returns the link destination if the entry is of type LINK. If the entry is not of type LINK, an empty string is returned.
RWCString name() const;
Returns the name of the entry.
int size() const;
Returns the size of the entry.
RWTime time() const;
Returns the time that the file was created. Typically, files that are more than a year old have only a creation date. For these entries, this method returns 12:00:00.
entryType type() const;
Returns the type of the entry.
ostream& operator<<(ostream& strm, const RWIDirEntry& de);
Outputs an RWIDirEntry object to an ostream in a common format.
Note: This class does not have an extraction (>>) operator.
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.