APathView#
An add-on to AStringView with functions for working with the path.
| Header: | #include <AUI/IO/APathView.h> |
| CMake: | aui_link(my_target PUBLIC aui::core) |
Detailed Description#
Note
In most file systems, both a regular file and a folder with the same name can exist on the same path.
Example usage:
APathView someDir = "someDir";
APath filePath = someDir / "myfile.txt"; // "/" replaced with a system file separator
Note
Sometimes the word "file" refers to both a regular file (txt, png, jpeg, etc.) and a folder (directory, a file that contains other regular files and folders), i.e. a unit of the file system, which is often a confusion in terminology. Here and further:
- file - a unit of the file system.
- regular file - a file that can be read or written to. You can think of as a sequence of bytes or a stream of bytes.
- folder (directory) - a file that may have child files (both regular files and folders)
Public Methods#
absolute#
APath APathView::absolute()
Get the absolute (full) path to the file.
- Returns
- the absolute (full) path to the file
chmod#
Changes mode (permissions) on file
- Arguments
newModenew mode.
It's convenient to use octet literal on newMode:
APath p("file.txt");
p.chmod(0755); // -rwxr-xr-x
exists#
- Returns
- true if whether regular file or a folder exists on this path
A file can exist as a regular file or(and) as a folder. This function will return false only if neither the folder nor the file does not exists on this path.
Checkout the isRegularFileExists or isDirectoryExists function to check which
type of the file exists on this path.
extension#
AStringView APathView::extension()
File extension.
- Returns
- file extension
`/home/user/file.cpp -> cpp
extensionChanged#
APath APathView::extensionChanged(AStringView newExtension)
Returns same path but with extension changed.
file#
APath APathView::file(AStringView fileName)
Path of the child element. Relevant only for folders.
- Arguments
fileNamename of child file- Returns
- path to child file relatively to this folder
with fileName = work: /home/user -> /home/user/work
It's convient to use / syntax instead:
APath("/home/user") / "work"
Examples:
examples/basic/hello_world/CMakeLists.txt
Console Hello World Example - Basic CLI Hello World application.
examples/app/game_of_life/CMakeLists.txt
Game of Life - Game of Life implementation that uses advanced large dynamic data rendering techniques such as [ITexture], [AImage] to be GPU friendly. The computation is performed in [AThreadPool].
examples/app/notes/CMakeLists.txt
Notes App - Note taking app that demonstrates usage of AListModel, AProperty, user data saving and loading.
examples/ui/views/CMakeLists.txt
Views Example - All-in-one views building example.
filename#
File name.
- Returns
- file name
/home/user/file.cpp -> file.cpp
filenameWithoutExtension#
File name without extension.
- Returns
- file name without extension
`/home/user/file.cpp -> file
isAbsolute#
Checks whether path absolute or not.
- Returns
- true if path is absolute
isDirectoryExists#
- Returns
- true if folder exists on this path
A file can exist as a regular file or(and) as a folder. This function will return false only if folder does not exists on this path.
isEffectivelyAccessible#
Return true if the current process has specified access flags to path.
Checks permissions and existence of the file identified by this APath using the real user and group identifiers of the process, like if the file were opened by open().
Using this function to check a process's permissions on a file before performing some operation based on that information leads to race conditions: the file permissions may change between the two steps. Generally, it is safer just to attempt the desired operation and handle any permission error that occurs.
isRegularFileExists#
- Returns
- true if regular file exists on this path
A file can exist as a regular file or(and) as a folder. This function will return false only if regular file does not exists on this path.
isRelative#
Checks whether path absolute or not.
- Returns
- true if path is relative
listDir#
Get list of (by default) direct children of this folder. This function outputs paths including the path listDir was called on.
- Returns
- list of children of this folder.
Use AFileListFlags enum flags to customize behaviour of this function.
makeDir#
Create folder.
- Returns
- this
makeDirs#
Create all nonexistent folders on the path.
- Returns
- this
operator#
APath APathView::operator(AStringView filename)
Path of the child element. Relevant only for folders.
- Arguments
- Returns
- path to child file relatively to this folder
Examples:
examples/7guis/cells/src/AST.cpp
7GUIs Cells - Spreadsheet processor (Excel).
parent#
APath APathView::parent()
- Returns
- path to parent folder
/home/user -> /home
Examples:
examples/ui/views/tests/LayoutManagerTest.cpp
Views Example - All-in-one views building example.
relativelyTo#
AString APathView::relativelyTo(APathView dir)
Returns same path but without dir
- Arguments
dirsome parent, grandparent, grandgrandparent... dir- Returns
- same path but without
dir
APath("C:/work/mon/test.txt").relativelyTo("C:/work") -> mon/test.txt
removeDirContentsRecursive#
Delete directory contents (recursively).
- Returns
- this
If this APath points to a regular file, the function has no effect. If this APath points to a directory, it removes all contained files (recursively) within that directory but does not remove the directory itself.
If the target does not exist, this function has no effect.
removeFile#
Delete file. Relevant for empty folders and regular files.
- Returns
- this
Unlike remove*Recursive functions, this function has no checks before proceeding, thus, it might throw AIOException (including if the target does not exist).
removeFileRecursive#
Delete files recursively, including itself.
- Returns
- this
If this APath points to a regular file, it deletes the file directly. If this APath points to a directory, it first removes all its contents (recursively) before potentially deleting the directory itself.
If the target does not exist, this function has no effect.
systemSlashDirection#
AString APathView::systemSlashDirection()
Transforms this path to string with platform's native slashes.
touch#
- Returns
- this.
Creates a file.
withoutUppermostFolder#
APath APathView::withoutUppermostFolder()
Remove the uppermost folder from this path
- Returns
- The same path except uppermost folder
v1.0.0/client/azaza.zip -> client/azaza.zip