Module: Internet Protocols Module Package: Internet Basics
Does not inherit
entryType getData() getError() |
getLink() getName() getSize() |
getTime() getType() isValid() |
RWDirEntry() |
#include <rw/internet/RWDirEntry.h>
RWDirEntry is a convenience class. It encapsulates parsing and component storage of directory entries typical of those returned from the FTP LIST command. The directory entry format is usually some variation of the UNIX ls long format. RWDirEntry is robust in its ability to make sense of the data passed to it. RWDirEntry 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 |
If the owner and/or group field is missing, the parsing mechanism provides empty defaults. Data type 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, the object is set to the invalid state and an error text message is saved. This message is available through the getError() method. If the directory entry parse fails, a copy of the original input string is available through the data method.
#include <rw/rstream.h> #include <rw/cstring.h> #include <rw/network/RWWinSockInfo.h> #include <rw/internet/RWDirEntry.h> int main() { RWWinSockInfo info; RWCString text = "lrwxr-xr-x 1 fred staff 512 Jan 10 1990 data -> /data2" RWDirEntry de = RWDirEntry(text); cout << de.getName() << endl; cout << de.getTime() << endl; cout << de.getLink() << endl; return 0; }
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 RWDirEntry object.
The former enum values (DIRECTORY, LINK, FILE, UNKNOWN) have been retained, but are deprecated. You can refuse support for these values by defining the macro RW_AVOID_PREPROCESSOR_PROBLEMS.
RWDirEntry();
Constructs a default invalid directory entry.
RWDirEntry(const RWCString& text);
Constructs an RWDirEntry object from an RWCString.
RWCString getData() 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. The RWCString should contain 7-bit US-ASCII data.
RWCString getError() const;
Returns a text description of the error that was encountered during the directory entry parsing phase. The RWCString should contain 7-bit US-ASCII data.
RWCString getLink() 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. The RWCString should contain 7-bit US-ASCII data.
RWCString getName() const;
Returns the name of the entry. The RWCString should contain 7-bit US-ASCII data.
int getSize() const;
Returns the size of the entry.
RWTime getTime() const;
Returns the time that the file was created.
Typically, files that are at least one year old have only a creation date. For these entries, this method returns 12:00:00. For files less than one year old, the year is typically not specified -- the year is either the current or previous year, depending on the current date. For example, if the current date is 10/15 and the file date is 9/2 (no year), the year of the file is assumed to be the current year. If the current date is 1/4, and the file date is 9/2, the year of the file is assumed to be the previous year.
entryType getType() const;
Returns the type of the entry.
bool isValid() const;
Returns true if the entry was parsed successfully. If it was not, the getData() method can be used to retrieve the original text, and the getError() method can be used to return a text description of the parse error.
ostream& operator<<(ostream& strm, const RWDirEntry& de);
Outputs an RWDirEntry object to an ostream in a common format.
NOTE -- This class does not have an extraction (>>) operator.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.