SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches

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 &)
 

Detailed Description

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.

Example
#include <rw/internet/RWDirEntry.h>
#include <rw/network/RWWinSockInfo.h>
#include <rw/cstring.h>
#include <rw/rstream.h>
int main() {
RWCString text =
"lrwxr-xr-x 1 fred staff 512 Jan 10 1990 data -> /data2";
RWDirEntry de = RWDirEntry(text);
cout << de.getName() << endl;
cout << de.getDateTime() << endl;
cout << de.getLink() << endl;
return 0;
}
Offers powerful and convenient facilities for manipulating strings.
Definition stdcstring.h:826
A convenience class that encapsulates parsing and component storage of directory entries typical of t...
Definition RWDirEntry.h:118
RWCString getLink() const
RWCString getName() const
RWDateTime getDateTime() const
Initializes the Winsock DLL on Windows platforms.
Definition RWWinSockInfo.h:49

Program Output

data
01/10/90 12:00:00
/data2

Member Enumeration Documentation

◆ entryType

Enumerates the possible file types in the file field of an RWDirEntry object.

Enumerator
DIRECTORY 
Deprecated
As of SourcePro 1, use ftype_directory instead.

Entry is a directory.

LINK 
Deprecated
As of SourcePro 1, use ftype_link instead.

Entry is a link.

FILE 
Deprecated
As of SourcePro 1, use ftype_file instead.

Entry is a file.

UNKNOWN 
Deprecated
As of SourcePro 1, use ftype_unknown instead.

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.

Constructor & Destructor Documentation

◆ RWDirEntry() [1/2]

RWDirEntry::RWDirEntry ( )

Constructs a default invalid directory entry.

◆ RWDirEntry() [2/2]

RWDirEntry::RWDirEntry ( const RWCString & line)

Constructs an RWDirEntry object from an RWCString.

Member Function Documentation

◆ getData()

RWCString RWDirEntry::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.

◆ getDateTime()

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.

◆ getError()

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.

◆ getLink()

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.

◆ getName()

RWCString RWDirEntry::getName ( ) const

Returns the name of the entry. The RWCString should contain 7-bit US-ASCII data.

◆ getSize()

int RWDirEntry::getSize ( ) const

Returns the size of the entry.

◆ getTime()

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.

Deprecated
As of SourcePro 10, use getDateTime() instead.

◆ getType()

entryType RWDirEntry::getType ( ) const

Returns the type of the entry.

◆ isValid()

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.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & str,
const RWDirEntry &  )
friend

Outputs an RWDirEntry object to an std::ostream in a common format.

Note
This class does not have an extraction (>>) operator.

Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.