Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site













SourceForge.net Logo

File path utilities

 

 

FileTime

 

struct FileTime : public CompareRelOps<const FileTime&, &Compare_FileTime> 

FileTime is a structure that encapsulates host specific type used for file or directory timestamps.

It has defined ordering and can be compared to Time. Time has conversion constructor from FileTime and AsFileTime method for backwards conversion.

 

 

Function List

 

bool PatternMatch(const char *p, const char *s)

Matches filename pattern p with filename s. Pattern can use wildcard characters '?', matching any single character or '*' matching any number of any characters (these wildcards are consistent with unix/windows). If pattern ends with '.', there must be no '.' in s (filename cannot have extension).

 


 

bool PatternMatchMulti(const char *p, const char *s)

Matches multiple patterns separated by semicolon (';') in p with filename s, using PatternMatch.

 


 

const char *GetFileNamePos(const char *path)

Returns the pointer to the first character of filename in path - the character after the last path separator ('/' in POSIX, '\\' or '/' in Win32). If there is no such character, returns path.

 


 

const char *GetFileExtPos(const char *path)

If filename in path has any extension (in fact, contains one or more '.' charactera), returns the pointer to the last '.', otherwise returns pointer to terminating '\0'.

 


 

bool HasFileExt(const char *path)

Returns true if path ends with filename with extension (in other words, if filename contains '.').

 


 

bool HasWildcards(const char *path)

Returns true if path contains '*' or '?' characters (wildcards).

 


 

bool IsFullPath(const char *path)

Returns true if path is absolute - starting with '/' in POSIX system or drive letter in Win32.

 


 

String GetFileDirectory(const char *path)

Extracts a directory path from path - a substring that ends with last path separator ('/' in POSIX, '/' or '\\' in Win32). Separator is included at the end of result. If there is none, returns empty string.

Example (POSIX): GetFileDirectory("/home/user/test.ext") returns "/home/user/".

 

 


 

String GetFileFolder(const char *path)

Extracts a directory path from path - a substring that ends with last path separator ('/' in POSIX, '/' or '\\' in Win32). Separator is not included at the end of result. If there is none, returns empty string.

Example (POSIX): GetFileFolder("/home/user/test.ext") returns "/home/user".

 


 

String GetFileTitle(const char *path)

Gets the name of file in path without extension (if any).

Example (POSIX): GetFileTitle("/home/user/test.ext") returns "test".

 


 

String GetFileExt(const char *path)

Gets file extension, including '.' character. If there is no extension, returns empty string.

Example (POSIX): GetFileExt("/home/user/test.ext") returns ".ext".

 


 

String GetFileName(const char *path)

Returns the name of file (without directory).

Example (POSIX): GetFileName("/home/user/test.ext") returns "test.ext".

 


 

String AppendFileName(const String& path, const char *filename)

Appends a filename to directory path. The main purpose of this operation is to maintain correct path separator. path is allowed but not required to end with separator.

 


 

String WinPath(const char *path)

Converts '/' in path to '\\'.

 


 

String UnixPath(const char *path)

Converts '\\' in path to '/'.

 


 

String NativePath(const char *path)

Same as WinPath in Win32 or UnixPath in POSIX.

 


 

String AppendExt(const char *path, const char *ext)

If path does not have extension, appends ext. Returns result.

 


 

String ForceExt(const char *path, const char *ext)

Changes file extension of path to ext. If there is no extension, appends it. Returns result.

 


 

String GetFileOnPath(const char *file, const char *paths, bool current = true, const char *curdir = NULL)

Attempts to find a file on semicolon separated list directory paths. If current is true, curdir.is added to this list. If curdir is NULL, the real current directory (obtained using GetCurrentDirectory) is used instead.

 


 

String GetCurrentDirectory()

Returns the current directory.

 


 

int64 GetFileLength(const char *path)

Returns the length of file at path or negative number if file does not exist.

 


 

bool FileExists(const char *path)

Returns true if path represents a file.

 


 

bool DirectoryExists(const char *path)

Returns true if path represents a directory.

 


 

FileTime GetFileTime(const char *path)

Returns the last write time of file at path. If item does not exist, result is set to zero (using memset, as FileTime is structure in Win32).

 


 

Time FileGetTime(const char *path)

Returns the last write time of file at path or Null if file does not exist.

 


 

bool SetFileTime(const char *path, FileTime ft)

Sets the last write time of file at path to ft.

 


 

bool FileSetTime(const char *path, Time time)

Sets the last write time of file at path to time.

 


 

FileTime TimeToFileTime(Time time)

Converts Time to FileTime.

 


 

bool FileCopy(const char *oldpath, const char *newpath)

Copies a file at oldpath to a new file at newpath (if already exists, overwrites it). Returns true on success.

 


 

bool FileMove(const char *oldpath, const char *newpath)

Moves a file at oldpath to a new file at newpath (if already exists, overwrites it). Returns true on success.

 


 

bool FileDelete(const char *path)

Deletes file at path. Returns true on success.

 


 

bool DirectoryCreate(const char *path, int mode = 0755)

[POSIX]

Creates new directory at path with access mode.

 


 

bool RealizeDirectory(const String& path, int mode = 0755)

[POSIX]

Creates all missing directories on path with access mode.Remember that path is a file path. To realize a folder path, it has be ended with a '\\'.

 


 

bool RealizePath(const String& path, int mode = 0755)

[POSIX]

Same as RealizeDirectory(GetFileFolder(path), mode) - creates all directories required before writing file at path.Remember that path is a file path. To realize a folder path, it has be ended with a '\\'.

 


 

bool DirectoryCreate(const char *path)

[Win32]

Creates new directory.

 


 

bool RealizeDirectory(const String& path)

[Win32]

Creates all missing directories on path.Remember that path is a file path. To realize a folder path, it has be ended with a '\\'.

 


 

bool RealizePath(const String& path)

[Win32]

Same as RealizeDirectory(GetFileFolder(path)) - creates all directories required before writing file at path. Remember that path is a file path. To realize a folder path, it has be ended with a '\\'.

 


 

bool DirectoryDelete(const char *path)

Deletes a directory at path. Returns true on success.

 


 

String NormalizePath(const char *path, const char *currdir)

Converts path to normalized format. If path is relative, it is converted to absolute using currdir as reference point. All ".." and "." segments of path are resolved and removed from the result.

 


 

String NormalizePath(const char *path)

Same as NormalizePath(path., GetCurrentDirectory()).

 


 

bool PathIsEqual(const char *p1, const char *p2)

Returns true if p1 and p2 identify the same file or directory. Both paths can be relative (current directory is then used as reference point) and can contain segments "." or "..".

 


 

bool DeleteFolderDeep(const char *dir)

Removes dir and everything it contains. Returns true on success.

 


 

String GetTempPath()

Returns a path to directory suitable for storing temporary files.

 


 

String GetTempFileName(const char *prefix = NULL)

Returns a unique path of temporary file. If prefix is not NULL, it is prepended to the filename.

 

 

Do you want to contribute?