#include <Pt/System/FileInfo.h>
Provides information about a node in the file-system. More...
Public Types | |
| enum | Type { Invalid = 0, Directory = 1, File = 2, Link = 4 } |
| File-node type. More... | |
| enum | Perms { NoPerms = 0, OwnerRead = 0400, OwnerWrite = 0200, OwnerExec = 0100, OwnerAll = 0700, GroupRead = 040, GroupWrite = 020, GroupExec = 010, GroupAll = 070, OthersRead = 04, OthersWrite = 02, OthersExec = 01, OthersAll = 07, AllPerms = 0777, SetUid = 04000, SetGid = 02000, StickyBit = 01000, PermMask = 07777, UnknownPerms = 0xFFFF } |
| File permission flags. More... | |
| enum | PermOptions { PermReplace = 1, PermAdd = 2, PermRemove = 4, PermNoFollow = 8 } |
| Options for modifying permissions. More... | |
Public Member Functions | |
| FileInfo () | |
| Default constructor. | |
| FileInfo (const Path &path) | |
| Constructs from the path. | |
| FileInfo (const Pt::String &path) | |
| Constructs from the path. | |
| FileInfo (const char *path) | |
| Constructs from the path. | |
| ~FileInfo () | |
| Destructor. | |
| void | clear () |
| Clears the state. | |
| const Path & | path () const |
| Returns the full path of node in the file-system. More... | |
| Pt::uint64_t | size () const |
| Returns the file size. | |
| Type | type () const |
| Returns the file type. | |
| Perms | permissions () const |
| Returns the file permissions. | |
Static Public Member Functions | |
| static Type | type (const Path &path) |
| Returns the type of file at the path. | |
| static Pt::uint64_t | size (const Path &path) |
| Returns the size of the file in bytes. | |
| static DateTime | lastModified (const Path &path) |
| Returns the time when last modified. | |
| static Perms | permissions (const Path &path) |
| Returns the permissions of the file at the path. | |
| static void | permissions (const Path &path, Perms prms, PermOptions opts=PermReplace) |
| Sets the permissions of the file at the path. More... | |
| static bool | exists (const Path &path) |
| Returns true if a file or directory exists at the path. | |
| static void | createFile (const Path &path) |
| Creates a new file. | |
| static void | createSymlink (const Path &target, const Path &link) |
| Creates a symbolic link at link pointing to target. | |
| static void | createHardlink (const Path &target, const Path &link) |
| Creates a hard link at link pointing to target. | |
| static void | createDirectory (const Path &path) |
| Creates a new directory. | |
| static void | createDirectories (const Path &path) |
| Creates a new directory. | |
| static void | resize (const Path &path, Pt::uint64_t n) |
| Resizes a file. | |
| static void | remove (const Path &path) |
| Removes a file or directory. | |
| static void | removeAll (const Pt::System::Path &path) |
| Removes a directory and its contents. | |
| static void | move (const Path &path, const Path &to) |
| Moves a file or directory. | |
Related Functions | |
| FileInfo::Perms | operator| (FileInfo::Perms a, FileInfo::Perms b) |
| Bitwise OR for FileInfo permission flags. | |
| FileInfo::Perms | operator& (FileInfo::Perms a, FileInfo::Perms b) |
| Bitwise AND for FileInfo permission flags. | |
| FileInfo::Perms | operator^ (FileInfo::Perms a, FileInfo::Perms b) |
| Bitwise XOR for FileInfo permission flags. | |
| FileInfo::Perms | operator~ (FileInfo::Perms a) |
| Bitwise NOT for FileInfo permission flags. | |
| FileInfo::Perms & | operator|= (FileInfo::Perms &a, FileInfo::Perms b) |
| Bitwise OR assignment for FileInfo permission flags. | |
| FileInfo::Perms & | operator&= (FileInfo::Perms &a, FileInfo::Perms b) |
| Bitwise AND assignment for FileInfo permission flags. | |
| FileInfo::PermOptions | operator| (FileInfo::PermOptions a, FileInfo::PermOptions b) |
| Bitwise OR for FileInfo permission options. | |
| bool | operator< (const FileInfo &a, const FileInfo &b) |
| Compare two FileInfo objects. | |
| bool | operator== (const FileInfo &a, const FileInfo &b) |
| Compare two FileInfo objects. | |
| bool | operator!= (const FileInfo &a, const FileInfo &b) |
| Compare two FileInfo objects. | |
The Pt::System::FileInfo class provides operations to query information about files and directories in the file system and to add, remove and modify them. FileInfo objects can be created with a path, are assignable, comparable and can be used as keys for e.g. std::map. The path needs not to refer to existing items in the file system, when a FileInfo object is constructed. It can be checked whether a file exists and what type of file it is, as shown in the following example:
Most operations are available as non-member functions, so it is not neccessary to create temporary FileInfo objects. Only the paths to files or directories are required to perform file system operations. The next example illustrates some of the non-member functions for file operations:
The code shown above creates a file, moves it to a new location and finally deletes it. If an operation fails, for example because the file could not be created, an exception of type AccessFailed is thrown. This is also the case for all other operations such as size(), createFile(), createDirectory(), resize() and remove(). The exception reports the name of the resource that could not be accessed.
| enum Type |
| enum Perms |
| enum PermOptions |
| const Path& path | ( | ) | const |
This method may return a relative path, or a fully qualified one depending on how this object was constructed.
|
static |
The opts parameter controls how the permissions are applied. Use PermReplace to set permissions exactly, PermAdd to add bits, or PermRemove to remove bits. Combine with PermNoFollow using bitwise OR to act on the symbolic link itself.