Guiliani  Version 2.6 revision 7293 (documentation build 12)
CGUIDirectory Class Referenceabstract

Allows accessing a directory, listing its contents and manipulate the contained files and directories. More...

#include <GUIDirectory.h>

Inheritance diagram for CGUIDirectory:

Public Types

enum  Filter_t {
  DIRECTORIES = 0x001 , FILES = 0x002 , NOSYMLINK = 0x004 , READABLE = 0x008 ,
  WRITABLE = 0x010 , EXECUTABLE = 0x020 , HIDDEN = 0x040 , SYSTEM = 0x080 ,
  SYMLINK = 0x100 , ALL = 0x200
}
 
enum  SortFlag_t { NAME = 0x00 , TIME = 0x01 , SIZE = 0x02 , TYPE = 0x04 }
 
typedef eC_TListDoubleLinked< eC_String > StringList_t
 A list of strings.
 

Public Member Functions

 CGUIDirectory (const CGUIDirectory &kDirectory)
 
 CGUIDirectory (const eC_String &kPath, const StringList_t &kNameFilter, eC_UInt uiFilter=ALL, SortFlag_t eSort=NAME, eC_Bool bSortCaseInsensitive=true)
 
 CGUIDirectory (const eC_String &kPath="", const eC_String &kNameFilter="")
 
virtual ~CGUIDirectory ()
 
eC_Bool ChangeDirectory (const eC_String &kDirName)
 
eC_Bool ChangeToParentDir ()
 
virtual eC_Bool CheckExist () const =0
 
eC_UInt CountFiles ()
 
virtual eC_Bool CreateSubDir (const eC_String &kDirName)=0
 
eC_String GetAbsPath () const
 
const CGUIDirInfoGetDirInfo (const eC_String &kFilePath)
 
eC_String GetDirName () const
 
StringList_t GetEntryFileNameList ()
 
const CGUIDirInfo::DirInfoPtrList_tGetEntryInfoList ()
 
StringList_t GetEntryList ()
 
eC_UInt GetFilterAttr () const
 
StringList_t GetNameFilters () const
 
eC_Bool GetSortCaseInSensitive () const
 
SortFlag_t GetSortFlag () const
 
virtual eC_Bool IsAbsPath () const
 
virtual eC_Bool IsReadable () const =0
 
virtual eC_Bool IsRoot () const =0
 
void MakePathAbs ()
 
CGUIDirectoryoperator= (const CGUIDirectory &kDirectory)
 
void RefreshList ()
 
virtual eC_Bool RemoveFile (const eC_String &kFileName)=0
 
virtual eC_Bool RemoveSubDir (const eC_String &kDirName, eC_Bool bRecursive=false)=0
 
virtual eC_Bool RenameFile (const eC_String &kOldName, const eC_String &kNewName)=0
 
void RevertSortList ()
 
void SetFilter (eC_UInt uiFilter)
 
void SetListSpecialFileFlag (eC_Bool bListSpecialFile)
 
void SetNameFilters (const eC_String &kNameFilter)
 
void SetNameFilters (const StringList_t &kNameFilter)
 
void SetSortCaseInSensitive (eC_Bool bSortCaseInsensitive)
 
void SetSortFlag (SortFlag_t eSort)
 

Protected Member Functions

void FilterList ()
 
void FreeDirInfoList ()
 
virtual void ListFiles ()=0
 
void SortDirInfoList ()
 
void SortSubList (CGUIDirInfo::DirInfoPtrList_t &kList)
 

Protected Attributes

eC_Bool m_bListNeedRecreation
 
eC_Bool m_bListSpecialFile
 
eC_Bool m_bSortCaseInsensitive
 
eC_Bool m_bSortDirsFirst
 
SortFlag_t m_eSortFlag
 
eC_String m_kCurrentWorkingDir
 
CGUIDirInfo::DirInfoPtrList_t m_kDirectoriesList
 
CGUIDirInfo::DirInfoPtrList_t m_kDirInfoList
 
eC_String m_kDirPath
 
CGUIDirInfo::DirInfoPtrList_t m_kFilesList
 
StringList_t m_kNameFilters
 
eC_UInt m_uiFilter
 

Detailed Description

Allows accessing a directory, listing its contents and manipulate the contained files and directories.

An instance of a CGUIDirectory can be obtained by calling CGUIFileSysWrap::DirAlloc. It is possible to specify name filters, filter attributes and sort mechanism when creating a CGUIDirectory instance. The name filters, filter attributes and sort flags can be retrieved by the calling corresponding getter methods.

The absolute path and name of this directory can be determined with the method GetAbsPath() and GetDirName() methods. You can also check the directory's attributes to see whether it is readable, is a root directory and if it does exist at all in the file system. MakePathAbs() provides the possibility to make the path of the directory absolute.

For accessing the contents of a directory, call the method GetEntryInfoList(). A list of only the file names without additional information can be also obtained by calling the method GetEntryList(). Whether the special directory entries "." and ".." is determined by a flag that can be set with SetListSpecialFileFlag(). A single CGUIDirInfo pointer can be obtained by calling the method GetDirInfo(). It is possible to create sub directory, remove a file or subdirectory and rename files from this directory with the methods CreateSubDir(), RemoveFile(), RemoveSubDir() and RenameFile().

Member Enumeration Documentation

◆ Filter_t

Filters for directory contents. They are meant to be used as bit masks for bitwise-OR when creating a filter for the SetFilter() method. To check a single filter attribute for a directory, call GetFilterAttr() and bitwise-AND the single attribute with the result.

Enumerator
DIRECTORIES 

List the directories.

FILES 

List the files.

NOSYMLINK 

Do not include symlinks.

READABLE 

List the files that are readable.

WRITABLE 

List the files that are writable.

EXECUTABLE 

List files for which the application has execute access.

HIDDEN 

List the hidden files.

SYSTEM 

List the system files.

SYMLINK 

List the symlinks.

ALL 

List all the files and directories.

◆ SortFlag_t

The sort flag type that is specified to sort the CGUIDirInfo objects in the list.

Enumerator
NAME 

Sort by name.

TIME 

Sort by modification time.

SIZE 

Sort by file size.

TYPE 

Sort by file type.

Constructor & Destructor Documentation

◆ CGUIDirectory() [1/3]

CGUIDirectory::CGUIDirectory ( const eC_String &  kPath = "",
const eC_String &  kNameFilter = "" 
)

Builds up a directory with given path and name filter. If the given path is empty, the current working directory is used. If the name filter is empty, it means including all files.

Parameters
kPathThe given directory path.
kNameFilterThe filter string to filter the directory, this is saved in the name filter list.

◆ CGUIDirectory() [2/3]

CGUIDirectory::CGUIDirectory ( const eC_String &  kPath,
const StringList_t kNameFilter,
eC_UInt  uiFilter = ALL,
SortFlag_t  eSort = NAME,
eC_Bool  bSortCaseInsensitive = true 
)

Constructs a directory with path, that filters its entries by name filters and attributes using uiFilter. It also sorts the names using eSort. If path is an empty string, the current working directory is used. If the name filters are empty, that means to list all the files.

Parameters
kPathThe given directory path.
kNameFilterThe name filter to filter the files in the directory.
uiFilterThe filter attribute to filter the files in the directory, it is a combination of the Filter_t elements.
eSortThe sort flag to sort the files in the directory.
bSortCaseInsensitiveCombined with sort flag sort the dir info case-insensitive or not.

◆ CGUIDirectory() [3/3]

CGUIDirectory::CGUIDirectory ( const CGUIDirectory kDirectory)

Copy constructor.

Parameters
kDirectoryThe source to be copied.

◆ ~CGUIDirectory()

virtual CGUIDirectory::~CGUIDirectory ( )
virtual

Destructor.

Member Function Documentation

◆ ChangeDirectory()

eC_Bool CGUIDirectory::ChangeDirectory ( const eC_String &  kDirName)

Changes the current directory to the given directory. If the given directory does not exist or is not readable, this method does nothing and returns False.

Note
This method does not work relatively to the current path of this directory object. Instead, the given directory name is run through MakePlatformPath() and used as the new directory here.
Parameters
kDirNameThe directory name that the current directory switches to.
Returns
True if the new directory exists and is readable; otherwise False.

◆ ChangeToParentDir()

eC_Bool CGUIDirectory::ChangeToParentDir ( )

Changes the current directory by moving one directory up from the current directory. If it is already the root node, it will not change anymore and return False. If the given directory does not exist and is not readable, this method does nothing and returns False.

Returns
True if the new directory exists and is readable; otherwise returns False.

◆ CheckExist()

virtual eC_Bool CGUIDirectory::CheckExist ( ) const
pure virtual

Checks whether this directory exists in the file system.

Returns
True if the directory exists, otherwise False.

Implemented in CGUIDirectoryPOSIX, and CGUIDirectoryWin.

◆ CountFiles()

eC_UInt CGUIDirectory::CountFiles ( )
inline

Counts the total number of directories and files in this directory after the directory is filtered and sorted.

Returns
The total number of directories and files in this directory.

◆ CreateSubDir()

virtual eC_Bool CGUIDirectory::CreateSubDir ( const eC_String &  kDirName)
pure virtual

Creates a sub-directory in this directory.

Parameters
kDirNameThe given directory name.
Returns
True on success; otherwise False.

Implemented in CGUIDirectoryPOSIX, and CGUIDirectoryWin.

◆ FilterList()

void CGUIDirectory::FilterList ( )
protected

Helper function for filtering the list. Specializations of this class use this method as a helper for ListFiles.

◆ FreeDirInfoList()

void CGUIDirectory::FreeDirInfoList ( )
protected

Frees the list of CGUIDirInfo, which is allocated in this class.

◆ GetAbsPath()

eC_String CGUIDirectory::GetAbsPath ( ) const

Gets the absolute path of this directory.

Returns
Absolute path of this directory.

◆ GetDirInfo()

const CGUIDirInfo * CGUIDirectory::GetDirInfo ( const eC_String &  kFilePath)

Gets the CGUIDirInfo pointer for a given file path. If no file or directory with that name can be found, this method returns NULL. !!! Attention performance critical!!!. An internal directory listing will be generated. If the additional functionality of GUIDirInfo is not needed please use for example GETFILESYS.CheckIfFileOrDirectoryExists or similar.

Parameters
kFilePathThe file path that corresponds to the CGUIDirInfo pointer to be found. Attention: This path is case-sensitive!
Returns
The CGUIDirInfo pointer, or NULL no file or sub directory with the given name exists.

◆ GetDirName()

eC_String CGUIDirectory::GetDirName ( ) const

Gets the name of the directory without the path. For instance if the current directory is '/usr/bin', the returned is 'bin'. If the directory has no name, because for instance it is the root directory, an empty string is returned.

Returns
The directory name without the path.

◆ GetEntryFileNameList()

StringList_t CGUIDirectory::GetEntryFileNameList ( )

Gets a list of file name excluding leading path for the files in the directories according to the name filters, filter attributes and sort flag stored in the object.

Returns
The string list of the files in the directory.

◆ GetEntryInfoList()

const CGUIDirInfo::DirInfoPtrList_t & CGUIDirectory::GetEntryInfoList ( )
inline

Gets the list of directory infos related to the fields in the directory according to the name filters, filter attributes and sort flag stored in the object.

Returns
The CGUIDirInfo list of the files in the directory.

◆ GetEntryList()

StringList_t CGUIDirectory::GetEntryList ( )

Gets the list of names of this directory's entries according to the name filters, filter attributes and sort flag stored in the object.

Returns
The string list of the entries in the directory.

◆ GetFilterAttr()

eC_UInt CGUIDirectory::GetFilterAttr ( ) const
inline

Gets the filter attribute for filtering this directory. This result is a bitwise-ORed integer using the values of Filter_t.

Returns
The filter attribute.
See also
Filter_t.

◆ GetNameFilters()

StringList_t CGUIDirectory::GetNameFilters ( ) const
inline

Gets the name filter string list.

Returns
The name filter string list.

◆ GetSortCaseInSensitive()

eC_Bool CGUIDirectory::GetSortCaseInSensitive ( ) const
inline

Gets the sort case-insensitive flag.

Returns
The case-insensitive flag.

◆ GetSortFlag()

SortFlag_t CGUIDirectory::GetSortFlag ( ) const
inline

Gets the currently set sort criterion.

Returns
The sort flag.

◆ IsAbsPath()

virtual eC_Bool CGUIDirectory::IsAbsPath ( ) const
virtual

Checks whether this directory's path name is an absolute path or not.

Returns
True if the directory's path is absolute, otherwise False.

◆ IsReadable()

virtual eC_Bool CGUIDirectory::IsReadable ( ) const
pure virtual

Checks whether the given directory is readable or not.

Returns
True if the directory is readable, otherwise False.

Implemented in CGUIDirectoryPOSIX, and CGUIDirectoryWin.

◆ IsRoot()

virtual eC_Bool CGUIDirectory::IsRoot ( ) const
pure virtual

Checks whether the given directory is a root directory or not.

Returns
True if the directory is the root directory, otherwise False.

Implemented in CGUIDirectoryPOSIX, and CGUIDirectoryWin.

◆ ListFiles()

virtual void CGUIDirectory::ListFiles ( )
protectedpure virtual

Creates the list of CGUIDirInfo pointers.

Implemented in CGUIDirectoryPOSIX, and CGUIDirectoryWin.

◆ MakePathAbs()

void CGUIDirectory::MakePathAbs ( )

Converts the directory path to an absolute path. If it is already absolute nothing happens.

◆ operator=()

CGUIDirectory & CGUIDirectory::operator= ( const CGUIDirectory kDirectory)

Assignment operator.

Parameters
kDirectoryThe source to be copied.
Returns
The refence of this object.

◆ RefreshList()

void CGUIDirectory::RefreshList ( )

This method forces the refresh of the directory to recreate the directory info list.

◆ RemoveFile()

virtual eC_Bool CGUIDirectory::RemoveFile ( const eC_String &  kFileName)
pure virtual

Removes the file with the given name. The list of the dir info must then be regenerated.

Parameters
kFileNameThe given file name that is to be removed.
Returns
True if the file is removed successfully; otherwise False.

Implemented in CGUIDirectoryPOSIX, and CGUIDirectoryWin.

◆ RemoveSubDir()

virtual eC_Bool CGUIDirectory::RemoveSubDir ( const eC_String &  kDirName,
eC_Bool  bRecursive = false 
)
pure virtual

Removes the sub directory specified with the given directory name.

To delete the sub directory or its contents, the current user needs write permissions.

Parameters
kDirNameName of the directory to be deleted.
bRecursiveIf true, all sub directories and files are deleted. If false, the directory must be empty for this method to succeed.
Returns
True if successful; otherwise False.

Implemented in CGUIDirectoryPOSIX, and CGUIDirectoryWin.

◆ RenameFile()

virtual eC_Bool CGUIDirectory::RenameFile ( const eC_String &  kOldName,
const eC_String &  kNewName 
)
pure virtual

Renames a file or directory. The list of the dir info must be regenerated.

Parameters
kOldNameName of the file that is to be renamed.
kNewNameThe new file name.
Returns
True if successful; otherwise False.

Implemented in CGUIDirectoryPOSIX, and CGUIDirectoryWin.

◆ RevertSortList()

void CGUIDirectory::RevertSortList ( )

Reverts the order of dir info list.

◆ SetFilter()

void CGUIDirectory::SetFilter ( eC_UInt  uiFilter)

Sets the filter attribute that is used to filter the files in the directory.

Parameters
uiFilterThe given filter attribute. Use bitwise-OR-ed values of Filter_t to create this value.
See also
Filter_t.

◆ SetListSpecialFileFlag()

void CGUIDirectory::SetListSpecialFileFlag ( eC_Bool  bListSpecialFile)
inline

Sets the list special file flag to indicate whether the special directory "." and ".." should be included in the CGUIDirInfo list or not.

Parameters
bListSpecialFilePass true to enable listing of special entries.

◆ SetNameFilters() [1/2]

void CGUIDirectory::SetNameFilters ( const eC_String &  kNameFilter)

Sets one name filter string to filter the directory. The name filter list then contains only this string.

Parameters
kNameFilterThe given name filter string.

◆ SetNameFilters() [2/2]

void CGUIDirectory::SetNameFilters ( const StringList_t kNameFilter)

Sets the name filter string list.

Parameters
kNameFilterThe given name filter string list.

◆ SetSortCaseInSensitive()

void CGUIDirectory::SetSortCaseInSensitive ( eC_Bool  bSortCaseInsensitive)

Sets the sort case-insensitive flag to indicate whether to sort the dir info list with case-insensitive or not.

Parameters
bSortCaseInsensitiveThe case-insensitive flag.

◆ SetSortFlag()

void CGUIDirectory::SetSortFlag ( SortFlag_t  eSort)

Sets the sort flag to sort the files in the directory.

Parameters
eSortSort criterion to be applied when sorting the entry list.

◆ SortDirInfoList()

void CGUIDirectory::SortDirInfoList ( )
protected

Helper function for sorting the dir info list. It calls SortSubList and reorders the list.

◆ SortSubList()

void CGUIDirectory::SortSubList ( CGUIDirInfo::DirInfoPtrList_t kList)
protected

Helper function for sorting the directory list or file list.

Parameters
kListThe list to sort

Member Data Documentation

◆ m_bListNeedRecreation

eC_Bool CGUIDirectory::m_bListNeedRecreation
protected

Indicates whether the entry list must be recreated or not inside the ListFiles method. Normally, before the user tries to get information about a file in the directory, ListFiles function must be called. This function checks this parameter to see if the list should be regenerated or not.

◆ m_bListSpecialFile

eC_Bool CGUIDirectory::m_bListSpecialFile
protected

Indicates whether the special file "." and ".." should be included in the directory list or not. By default, they will not be included in the list.

◆ m_bSortCaseInsensitive

eC_Bool CGUIDirectory::m_bSortCaseInsensitive
protected

Combined with sort flag to sort the dir info list case-insensitive or not.

◆ m_bSortDirsFirst

eC_Bool CGUIDirectory::m_bSortDirsFirst
protected

Indicate in current directory sorting order, if the directories are placed in front of the files or not.

◆ m_eSortFlag

SortFlag_t CGUIDirectory::m_eSortFlag
protected

The sort flag for this directory.

◆ m_kCurrentWorkingDir

eC_String CGUIDirectory::m_kCurrentWorkingDir
protected

Stores the current working directory path.

◆ m_kDirectoriesList

CGUIDirInfo::DirInfoPtrList_t CGUIDirectory::m_kDirectoriesList
protected

The list stores only the directories.

◆ m_kDirInfoList

CGUIDirInfo::DirInfoPtrList_t CGUIDirectory::m_kDirInfoList
protected

The list stores the CGUIDirInfo object pointers, this is a combination of the directories list and files list.

◆ m_kDirPath

eC_String CGUIDirectory::m_kDirPath
protected

Stores this directory's path.

◆ m_kFilesList

CGUIDirInfo::DirInfoPtrList_t CGUIDirectory::m_kFilesList
protected

The list stores only the files (excluding the directories).

◆ m_kNameFilters

StringList_t CGUIDirectory::m_kNameFilters
protected

The name filters.

◆ m_uiFilter

eC_UInt CGUIDirectory::m_uiFilter
protected

The filter attribute for this directory. Combination of the Filter_t flags.


The documentation for this class was generated from the following file: