SourcePro® 2024.1 |
SourcePro® API Reference Guide |
A convenience class that encapsulates parsing and component storage of directory entries typical of those returned from the FTP LIST
command.
More...
#include <rw/internet/RWDirEntry.h>
Public Types | |
enum | entryType { DIRECTORY , LINK , FILE , UNKNOWN , ftype_directory , ftype_link , ftype_file , ftype_unknown } |
Public Member Functions | |
RWDirEntry () | |
RWDirEntry (const RWCString &line) | |
RWCString | getData () const |
RWDateTime | getDateTime () const |
RWCString | getError () const |
RWCString | getLink () const |
RWCString | getName () const |
int | getSize () const |
RWTime | getTime () const |
entryType | getType () const |
bool | isValid () const |
Friends | |
std::ostream & | operator<< (std::ostream &str, const RWDirEntry &) |
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 getData() method.
Program Output
Enumerates the possible file types in the file field of an RWDirEntry object.
Enumerator | |
---|---|
DIRECTORY |
Entry is a directory. |
LINK |
Entry is a link. |
FILE |
Entry is a file. |
UNKNOWN |
Entry is an unknown type. |
ftype_directory | Entry is a directory. |
ftype_link | Entry is a link. |
ftype_file | Entry is a file. |
ftype_unknown | Entry is an unknown type. |
RWDirEntry::RWDirEntry | ( | ) |
Constructs a default invalid directory entry.
RWDirEntry::RWDirEntry | ( | const RWCString & | line | ) |
Constructs an RWDirEntry object from an RWCString.
RWCString RWDirEntry::getData | ( | ) | const |
RWDateTime RWDirEntry::getDateTime | ( | ) | const |
Returns an RWDateTime object containing the date and 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.
RWCString RWDirEntry::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 RWDirEntry::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 RWDirEntry::getName | ( | ) | const |
Returns the name of the entry. The RWCString should contain 7-bit US-ASCII data.
int RWDirEntry::getSize | ( | ) | const |
Returns the size of the entry.
RWTime RWDirEntry::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 RWDirEntry::getType | ( | ) | const |
Returns the type of the entry.
bool RWDirEntry::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.
|
friend |
Outputs an RWDirEntry object to an std::ostream
in a common format.
Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved. |