Library: Foundation
Package: Filesystem
Header: Poco/File.h
The File class provides methods for working with a file.
Direct Base Classes: FileImpl
All Base Classes: FileImpl
Known Derived Classes: TemporaryFile
Member Functions: canRead, canWrite, copyTo, createDirectories, createDirectory, createFile, created, exists, getLastModified, getSize, isDirectory, isFile, isLink, list, moveTo, operator !=, operator <, operator <=, operator =, operator ==, operator >, operator >=, path, remove, renameTo, setLastModified, setReadOnly, setSize, setWriteable, swap
typedef FileSizeImpl FileSize;
File();
Creates the file.
File(
const std::string & path
);
Creates the file.
File(
const char * path
);
Creates the file.
Creates the file.
Copy constructor.
virtual ~File();
Destroys the file.
bool canRead() const;
Returns true iff the file is readable.
bool canWrite() const;
Returns true iff the file is writeable.
void copyTo(
const std::string & path
) const;
Copies the file to the given path. The target path can be a directory.
void createDirectories();
Creates a directory (and all parent directories if necessary).
bool createDirectory();
Creates a directory. Returns true if the directory has been created and false if it already exists. Throws an exception if an error occurs.
bool createFile();
Creates a new, empty file in an atomic operation. Returns true if the file has been created and false if the file already exists. Throws an exception if an error occurs.
Timestamp created() const;
Returns the creation date of the file.
bool exists() const;
Returns true iff the file exists.
Timestamp getLastModified() const;
Returns the modification date of the file.
FileSize getSize() const;
Returns the size of the file in bytes.
bool isDirectory() const;
Returns true iff the file is a directory.
bool isFile() const;
Returns true iff the file is a regular file.
bool isLink() const;
Returns true iff the file is a symbolic link.
void list(
std::vector < std::string > & files
) const;
Fills the vector with the names of all files in the directory.
void list(
std::vector < File > & files
) const;
Fills the vector with the names of all files in the directory.
void moveTo(
const std::string & path
);
Copies the file to the given path and removes the original file. The target path can be a directory.
bool operator != (
const File & file
) const;
bool operator < (
const File & file
) const;
bool operator <= (
const File & file
) const;
File & operator = (
const File & file
);
Assignment operator.
File & operator = (
const std::string & path
);
Assignment operator.
File & operator = (
const char * path
);
Assignment operator.
File & operator = (
const Path & path
);
Assignment operator.
bool operator == (
const File & file
) const;
bool operator > (
const File & file
) const;
bool operator >= (
const File & file
) const;
const std::string & path() const;
Returns the path.
void remove(
bool recursive = false
);
Deletes the file. If recursive is true and the file is a directory, recursively deletes all files in the directory.
void renameTo(
const std::string & path
);
Renames the file to the new name.
void setLastModified(
const Timestamp & ts
);
Sets the modification date of the file.
void setReadOnly(
bool flag = true
);
Makes the file non-writeable (if flag is true), or writeable (if flag is false) by setting the file's flags in the filesystem accordingly.
void setSize(
FileSize size
);
Sets the size of the file in bytes. Can be used to truncate a file.
void setWriteable(
bool flag = true
);
Makes the file writeable (if flag is true), or non-writeable (if flag is false) by setting the file's flags in the filesystem accordingly.
void swap(
File & file
);
Swaps the file with another one.