00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "ndir.h"
00023
00024 NDir::NDir(const NString &name)
00025 : NObject(),
00026 m_contents(),
00027 m_dir_name(name),
00028 m_dir_handle(NULL)
00029 {
00030 struct dirent *ent;
00031
00032 m_dir_handle = opendir(m_dir_name.toChar());
00033 if (!m_dir_handle) {
00034 throw NIOException(nerror(errno), m_dir_name,
00035 NException::BASEIO,
00036 NIOException::FILE,
00037 errno);
00038 }
00039
00040 ent = readdir(m_dir_handle);
00041 if (!ent) {
00042 if (errno != 0) {
00043 throw NIOException(nerror(errno), m_dir_name,
00044 NException::BASEIO,
00045 NIOException::FILE,
00046 errno);
00047 }
00048 }
00049
00050 loadContents(ent);
00051 }
00052
00053 NDir::~NDir(void) {
00054 closedir(m_dir_handle);
00055 }
00056
00057
00058 void NDir::loadContents(struct dirent *ent) {
00059 NString tmp_name;
00060
00061 while (ent) {
00062 NDebug::print() << "Entry name = " << ent->d_name;
00063
00064 tmp_name = ent->d_name;
00065 m_contents.append(tmp_name);
00066
00067
00068 seekdir(m_dir_handle, ent->d_off);
00069 ent = readdir(m_dir_handle);
00070 if (!ent) {
00071 if (errno != 0) {
00072 throw NIOException(nerror(errno), m_dir_name,
00073 NException::BASEIO,
00074 NIOException::FILE,
00075 errno);
00076 }
00077 }
00078 }
00079
00080 NDebug::print() << "Added " << m_contents.size() << " entries";
00081 }
00082
00083 NList<NString> NDir::getContents(void) const {
00084 return m_contents;
00085 }
00086
00087
00088 NString NDir::getName(void) const {
00089 return m_dir_name;
00090 }