wxPathList Class Reference | wxWidgets

| Version: 3.2.11

Loading...
Searching...
No Matches
Public Member Functions | List of all members
wxPathList Class Reference
Class List by Category » File Handling

`#include </cygdrive/c/Users/Hamis/Cygwin-packaging/wxWidgets3.2/wxWidgets3.2-3.2.11-1.x86_64/src/wxWidgets-3.2.11/interface/wx/filefn.h>`

Inheritance diagram for wxPathList:
[legend]

## Detailed Description

The path list is a convenient way of storing a number of directories, and when presented with a filename without a directory, searching for an existing file in those directories.

Be sure to look also at wxStandardPaths if you only want to search files in some standard paths.

##

Library: wxBase
Category: File Handling

See also
  wxArrayString, wxStandardPaths, wxFileName

## Public Member Functions
| wxPathList ()
| Standard constructor.
| wxPathList (const wxArrayString &arr)
| Constructs the object calling the Add() function.
bool | Add (const wxString &path)
| Adds the given directory to the path list, if the path is not already in the list.
void | Add (const wxArrayString &arr)
| Adds all elements of the given array as paths.
void | AddEnvList (const wxString &env_variable)
| Finds the value of the given environment variable, and adds all paths to the path list.
bool | EnsureFileAccessible (const wxString &filename)
| Given a full filename (with path), calls Add() with the path of the file.
wxString | FindAbsoluteValidPath (const wxString &file) const
| Like FindValidPath() but this function always returns an absolute path (eventually prepending the current working directory to the value returned wxPathList::FindValidPath()) or an empty string.
wxString | FindValidPath (const wxString &file) const
| Searches the given file in all paths stored in this class.
Public Member Functions inherited from wxArrayString
| wxArrayString ()
| Default constructor.
| wxArrayString (const wxArrayString &array)
| Copy constructor.
| wxArrayString (size_t sz, const char **arr)
| Constructor from a C string array.
| wxArrayString (size_t sz, const wchar_t **arr)
| Constructor from a C wide string array.
| wxArrayString (size_t sz, const wxString *arr)
| Constructor from a wxString array.
template<typename T>
| wxArrayString (std::initializer_list< T > list)
| Constructs the container with the contents of the initializer_list list.
| ~wxArrayString ()
| Destructor frees memory occupied by the array strings.
size_t | Add (const wxString &str, size_t copies=1)
| Appends the given number of copies of the new item str to the array and returns the index of the first new item in the array.
void | Alloc (size_t nCount)
| Preallocates enough memory to store nCount items.
void | Clear ()
| Clears the array contents and frees memory.
void | Empty ()
| Empties the array: after a call to this function GetCount() will return 0.
size_t | GetCount () const
| Returns the number of items in the array.
int | Index (const wxString &str, bool bCase=true, bool bFromEnd=false) const
| Searches the array for str, starting from the beginning if bFromEnd is false or from the end otherwise.
void | Insert (const wxString &str, size_t nIndex, size_t copies=1)
| Inserts the given number of copies of str in the array before the array element at the position nIndex.
bool | IsEmpty () const
| Returns true if the array is empty, false otherwise.
void | Remove (const wxString &sz)
| Removes the first item matching this value.
void | RemoveAt (size_t nIndex, size_t count=1)
| Removes count items starting at position nIndex from the array.
void | Shrink ()
| Releases the extra memory allocated by the array.
void | Sort (bool reverseOrder=false)
| Sorts the array in alphabetical order or in reverse alphabetical order if reverseOrder is true.
void | Sort (CompareFunction compareFunction)
| Sorts the array using the specified compareFunction for item comparison.
bool | operator!= (const wxArrayString &array) const
| Compares 2 arrays respecting the case.
wxArrayString & | operator= (const wxArrayString &)
| Assignment operator.
bool | operator== (const wxArrayString &array) const
| Compares 2 arrays respecting the case.
wxString & | operator[] (size_t nIndex) const
| Returns the array element at position nIndex.
wxString & | Item (size_t nIndex)
| Return the array element at position nIndex.
const wxString & | Item (size_t nIndex) const
| Return the array element at position nIndex.
wxString & | Last ()
| Returns the last element of the array.
const wxString & | Last () const
| Returns the last element of the array.

## Additional Inherited Members
Public Types inherited from wxArrayString
typedef int(* | CompareFunction) (const wxString &first, const wxString &second)
| The function type used with wxArrayString::Sort().

## Constructor & Destructor Documentation

## ◆ wxPathList() [1/2]

wxPathList::wxPathList | ( |  | ) |

Standard constructor.

## ◆ wxPathList() [2/2]

wxPathList::wxPathList | ( | const wxArrayString & | arr | ) |

Constructs the object calling the Add() function.

## Member Function Documentation

## ◆ Add() [1/2]

void wxPathList::Add | ( | const wxArrayString & | arr | ) |

Adds all elements of the given array as paths.

## ◆ Add() [2/2]

bool wxPathList::Add | ( | const wxString & | path | ) |

Adds the given directory to the path list, if the path is not already in the list.

If the path cannot be normalized for some reason, it returns false.

The path is always considered to be a directory but no existence checks will be done on it (because if it doesn't exist, it could be created later and thus result a valid path when FindValidPath() is called).

Note
  if the given path is relative, it won't be made absolute before adding it (this is why FindValidPath() may return relative paths).

## ◆ AddEnvList()

void wxPathList::AddEnvList | ( | const wxString & | env_variable | ) |

Finds the value of the given environment variable, and adds all paths to the path list.

Useful for finding files in the `PATH` variable, for example.

## ◆ EnsureFileAccessible()

bool wxPathList::EnsureFileAccessible | ( | const wxString & | filename | ) |

Given a full filename (with path), calls Add() with the path of the file.

## ◆ FindAbsoluteValidPath()

wxString wxPathList::FindAbsoluteValidPath | ( | const wxString & | file | ) | const

Like FindValidPath() but this function always returns an absolute path (eventually prepending the current working directory to the value returned wxPathList::FindValidPath()) or an empty string.

## ◆ FindValidPath()

wxString wxPathList::FindValidPath | ( | const wxString & | file | ) | const

Searches the given file in all paths stored in this class.

The first path which concatenated to the given string points to an existing file (see wxFileExists()) is returned.

If the file wasn't found in any of the stored paths, an empty string is returned.

The given string must be a file name, eventually with a path prefix (if the path prefix is absolute, only its name will be searched); i.e. it must not end with a directory separator (see wxFileName::GetPathSeparator) otherwise an assertion will fail.

The returned path may be relative to the current working directory.

Note in fact that wxPathList can be used to store both relative and absolute paths so that if you added relative paths, then the current working directory (see wxGetCwd() and wxSetWorkingDirectory()) may affect the value returned by this function!