PFile Class Reference

Detailed Description

The PFile class is an helper class for file management.

You cannot create instances of PFile.

Definition at line 29 of file PFile.h.

#include <PFile.h>

Member Function Documentation

◆ CheckExistsAndIsExecutable()

static PResult PFile::CheckExistsAndIsExecutable ( const PString filename)
static

Returns PResult::C_OK if the specified file exists and is executable, another result otherwise.

See also
Exists()

◆ CheckExistsAndIsReadable()

static PResult PFile::CheckExistsAndIsReadable ( const PString filename,
papillon::int32  checkForGenericFile = -1 
)
static

Returns PResult::C_OK if the specified file exists and is readable, another result otherwise.

This function can also checks for generic file using the second (optional) argument. Example1: if the second argument is 0 and the filename is "images%04d.jpg", then the function will try to find the file "images0000.jpg". Example2: if the second argument is 99 and the filename is "images%04d.jpg", then the function will try to find any file in the list { "images0000.jpg" .. "images0099.jpg" }. It will return true if at least one of these files can be found.

Common idiom is the following:

PResult DoSomething(const PString& filename)
{
// ...
}
See also
Exists()
IsReadable()

◆ Copy()

static PResult PFile::Copy ( const PString sourceFilename,
const PString destinationFilename,
bool  overwriteIfExists = false 
)
static

Copies the specified file.

Returns PResult::C_OK if success, another result otherwise.

◆ Exists()

static bool PFile::Exists ( const PString filename)
static

Returns true if the specified file exists, false otherwise.

See also
PPath::IsPathExist()
CheckExistsAndIsReadable()

◆ GetAbsoluteFilePath()

static PString PFile::GetAbsoluteFilePath ( const PString filename)
static

Returns an absolute path including the file name.

The absolute path name consists of the full path and the file name. On Unix this will always begin with the root, '/', directory. On Windows this will always begin 'D:/' where D is a drive letter, except for network shares that are not mapped to a drive letter, in which case the path will begin '//sharename/'.

◆ GetAbsolutePath()

static PString PFile::GetAbsolutePath ( const PString filename)
static

Returns a file's path absolute path.

This doesn't include the file name. On Unix the absolute path will always begin with the root, '/', directory. On Windows this will always begin 'D:/' where D is a drive letter, except for network shares that are not mapped to a drive letter, in which case the path will begin '//sharename/'.

◆ GetFilenameWithoutPath()

static PString PFile::GetFilenameWithoutPath ( const PString filename)
static

Returns the filename without the path.

◆ GetLastModified()

static PDateTime PFile::GetLastModified ( const PString filename)
static

Returns the date and local time when the file was last modified.

◆ GetMD5()

static PString PFile::GetMD5 ( const PString filename)
static

DEPRECATED, use MD5() instead.

Computes the MD5 hash sum of the specified file or an empty string if the file does not exist or cannot be read. Note: the MD5 of an existing empty file is "d41d8cd98f00b204e9800998ecf8427e".

◆ GetSize()

static papillon::int64 PFile::GetSize ( const PString filename)
static

Returns the size of the specified file in bytes or 0 if the file does not exist.

◆ IsExecutable()

static bool PFile::IsExecutable ( const PString filename)
static

Returns true if the specified file exists AND is executable, false otherwise.

◆ IsReadable()

static bool PFile::IsReadable ( const PString filename)
static

Returns true if the specified file exists AND is readable, false otherwise.

See also
Exists()
CheckExistsAndIsReadable()

◆ IsWritable()

static bool PFile::IsWritable ( const PString filename)
static

Returns true if the specified file exists AND is writable, false otherwise.

◆ MD5()

static PString PFile::MD5 ( const PString filename)
static

Computes the MD5 hash sum of the specified file or an empty string if the file does not exist or cannot be read.

Note: the MD5 of an existing empty file is "d41d8cd98f00b204e9800998ecf8427e".

◆ RandomFilename() [1/2]

static PString PFile::RandomFilename ( )
static

Returns a random filename.

◆ RandomFilename() [2/2]

static PString PFile::RandomFilename ( const PString prefix,
const PString suffixOrExtension,
bool  inTemp = true 
)
static

Returns a random filename with the specified prefix and suffix/extension, either in the current working directory of in system's temporary directory (by default).

◆ Remove()

static PResult PFile::Remove ( const PString filename)
static

Removes the specified file.

Returns PResult::C_OK if success, another result otherwise.

◆ Rename()

static PResult PFile::Rename ( const PString oldName,
const PString newName 
)
static

Renames the specified file.

Returns PResult::C_OK if success, another result otherwise.

◆ Unzip()

static PResult PFile::Unzip ( const PString sourceFilename,
const PString destinationFilename,
bool  overwriteIfExists = false 
)
static

Uncompresses (unzip) the specified file.

Returns PResult::C_OK if success, another result otherwise.

◆ Zip()

static PResult PFile::Zip ( const PString sourceFilename,
const PString destinationFilename,
bool  overwriteIfExists = false 
)
static

Compresses (zip) the specified file.

Returns PResult::C_OK if success, another result otherwise.