See also the derived classes
RegularFile,
Directory, and
SymLink.
This class does not contain virtual functions, because a lot of functions
have different parameters, e.g. 'create' for RegularFile has one parameter
and 'create' for SymLink has two parameters.
It handles large files correctly.
File myFile("someFileName"); if (myFile.exists()) { myFile.setPermissions(0644); if (myFile.isRegular()) { cout << "this file is a regular file" << endl; } } else if (!myFile.exists()) { if (!myFile.canCreate()){ cout << "cannot create this file" << endl; } }
Construct a File object whose Path is set to the given Path.
Copy constructor (copy semantics).
Assignment (copy semantics).
Returns the pathname of the file.
Check if the file is a regular file. If the boolean followSymLink is False a symbolic link will not be followed.
Check if the file is a directory. If the boolean followSymLink is False a symbolic link will not be followed.
Check if the file is a symbolic link.
Check if the file is a pipe.
Check if the file is a character special file.
Check if the file is a block special file.
Check if the file is a socket.
Check if the file exists.
Check if the file is readable.
Check if the file is writable.
Check if the file is executable.
Check if a file can be created.
Return the userID of the file.
Return the groupID of the file.
Return the size of the file. If the file does not exist, an exception will be thrown.
Return the permissions as a decimal value.
Set permission with perm. Perm is an octal value.
Update access time and modification time of a file.
Update access time and modification time of a file. This function updates the file with the current time.
Time related fucnctions: Return the time when the file was last accessed in seconds since 00:00:00 GMT Jan 1, 1970.
Return the time when the file was last accessed as a 26-characters String of the form: Thu Feb 3 13:40:11 1994\n\0.
Return the time when the file was last modified in seconds since 00:00:00 GMT Jan 1, 1970.
Return the time when the file was last modified as a 26-characters String of the form: Thu Feb 3 13:40:11 1994\n\0.
Return the time when the file status was last changed in seconds since 00:00:00 GMT Jan 1, 1970. It is set both by writing and changing the file status information, such as changes of owner, group, link count, or mode.
return the time when the file status was last changed as a 26-characters String of the form: Thu Feb 3 13:40:11 1994\n\0
Create a new unique path name in the specified directory, with the specified prefix and random trailing characters:
p.newUniqueName ("./", "temp") --> "./tempAAA00xx32" p.newUniqueName ("/home/me", "diary") --> "/home/me/diaryAAA00xxb0"
Create a new unique filename without a prefix. As above, but all the characters in the filename are random:
p.newUniqueName ("./") --> "./AAA00xx32" p.newUniqueName ("/home/me") --> "/home/me/AAA00xxb0"
Check if the new path for a copy or move is valid.
An exception is thrown if:
- the target directory is not writable
- or the target file already exists and overwrite==False
- or the target file already exists and is not writable
When the targetName represents a directory, the basename
of the file is appended to it. This is done to cover the
case where the source is a symlink to a file. In that case
the target will get the basename of the symlink and not the
the basename of the file pointed to. This is not done when
forDirectory==True (which is used by class Directory).
Get the lstat of this file. Throw an exception when it fails.
Get the lstat of a file. Throw an exception when it fails.