Allows accessing a directory, listing its contents and manipulate the contained files and directories. More...
#include <GUIDirectory.h>
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 CGUIDirInfo * | GetDirInfo (const eC_String &kFilePath) |
eC_String | GetDirName () const |
StringList_t | GetEntryFileNameList () |
const CGUIDirInfo::DirInfoPtrList_t & | GetEntryInfoList () |
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 () |
CGUIDirectory & | operator= (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 |
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().
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.
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. |
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.
kPath | The given directory path. |
kNameFilter | The filter string to filter the directory, this is saved in the name filter list. |
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.
kPath | The given directory path. |
kNameFilter | The name filter to filter the files in the directory. |
uiFilter | The filter attribute to filter the files in the directory, it is a combination of the Filter_t elements. |
eSort | The sort flag to sort the files in the directory. |
bSortCaseInsensitive | Combined with sort flag sort the dir info case-insensitive or not. |
CGUIDirectory::CGUIDirectory | ( | const CGUIDirectory & | kDirectory | ) |
Copy constructor.
kDirectory | The source to be copied. |
|
virtual |
Destructor.
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.
kDirName | The directory name that the current directory switches to. |
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.
|
pure virtual |
Checks whether this directory exists in the file system.
Implemented in CGUIDirectoryPOSIX, and CGUIDirectoryWin.
|
inline |
Counts the total number of directories and files in this directory after the directory is filtered and sorted.
|
pure virtual |
Creates a sub-directory in this directory.
kDirName | The given directory name. |
Implemented in CGUIDirectoryPOSIX, and CGUIDirectoryWin.
|
protected |
Helper function for filtering the list. Specializations of this class use this method as a helper for ListFiles.
|
protected |
Frees the list of CGUIDirInfo, which is allocated in this class.
eC_String CGUIDirectory::GetAbsPath | ( | ) | const |
Gets the absolute path of this directory.
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.
kFilePath | The file path that corresponds to the CGUIDirInfo pointer to be found. Attention: This path is case-sensitive! |
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.
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.
|
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.
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.
|
inline |
Gets the filter attribute for filtering this directory. This result is a bitwise-ORed integer using the values of Filter_t.
|
inline |
Gets the name filter string list.
|
inline |
Gets the sort case-insensitive flag.
|
inline |
Gets the currently set sort criterion.
|
virtual |
Checks whether this directory's path name is an absolute path or not.
|
pure virtual |
Checks whether the given directory is readable or not.
Implemented in CGUIDirectoryPOSIX, and CGUIDirectoryWin.
|
pure virtual |
Checks whether the given directory is a root directory or not.
Implemented in CGUIDirectoryPOSIX, and CGUIDirectoryWin.
|
protectedpure virtual |
Creates the list of CGUIDirInfo pointers.
Implemented in CGUIDirectoryPOSIX, and CGUIDirectoryWin.
void CGUIDirectory::MakePathAbs | ( | ) |
Converts the directory path to an absolute path. If it is already absolute nothing happens.
CGUIDirectory & CGUIDirectory::operator= | ( | const CGUIDirectory & | kDirectory | ) |
Assignment operator.
kDirectory | The source to be copied. |
void CGUIDirectory::RefreshList | ( | ) |
This method forces the refresh of the directory to recreate the directory info list.
|
pure virtual |
Removes the file with the given name. The list of the dir info must then be regenerated.
kFileName | The given file name that is to be removed. |
Implemented in CGUIDirectoryPOSIX, and CGUIDirectoryWin.
|
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.
kDirName | Name of the directory to be deleted. |
bRecursive | If true, all sub directories and files are deleted. If false, the directory must be empty for this method to succeed. |
Implemented in CGUIDirectoryPOSIX, and CGUIDirectoryWin.
|
pure virtual |
Renames a file or directory. The list of the dir info must be regenerated.
kOldName | Name of the file that is to be renamed. |
kNewName | The new file name. |
Implemented in CGUIDirectoryPOSIX, and CGUIDirectoryWin.
void CGUIDirectory::RevertSortList | ( | ) |
Reverts the order of dir info list.
void CGUIDirectory::SetFilter | ( | eC_UInt | uiFilter | ) |
Sets the filter attribute that is used to filter the files in the directory.
uiFilter | The given filter attribute. Use bitwise-OR-ed values of Filter_t to create this value. |
|
inline |
Sets the list special file flag to indicate whether the special directory "." and ".." should be included in the CGUIDirInfo list or not.
bListSpecialFile | Pass true to enable listing of special entries. |
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.
kNameFilter | The given name filter string. |
void CGUIDirectory::SetNameFilters | ( | const StringList_t & | kNameFilter | ) |
Sets the name filter string list.
kNameFilter | The given name filter string list. |
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.
bSortCaseInsensitive | The case-insensitive flag. |
void CGUIDirectory::SetSortFlag | ( | SortFlag_t | eSort | ) |
Sets the sort flag to sort the files in the directory.
eSort | Sort criterion to be applied when sorting the entry list. |
|
protected |
Helper function for sorting the dir info list. It calls SortSubList and reorders the list.
|
protected |
Helper function for sorting the directory list or file list.
kList | The list to sort |
|
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.
|
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.
|
protected |
Combined with sort flag to sort the dir info list case-insensitive or not.
|
protected |
Indicate in current directory sorting order, if the directories are placed in front of the files or not.
|
protected |
The sort flag for this directory.
|
protected |
Stores the current working directory path.
|
protected |
The list stores only the directories.
|
protected |
The list stores the CGUIDirInfo object pointers, this is a combination of the directories list and files list.
|
protected |
Stores this directory's path.
|
protected |
The list stores only the files (excluding the directories).
|
protected |
The name filters.
|
protected |
The filter attribute for this directory. Combination of the Filter_t flags.