Declaration (see MFile.h):
void truncate(MFileSize cnt);
Truncates an open local by cnt bytes (works only on local files).
The number of bytes to truncate.
If the file is an online file (FTP or HTTP), or if it was opened in an fmRead mode (see open), then truncate generates exception 2001 and quits. If an I/O error occurs, the function generates exception 2007 and quits. The file is closed on any error.
On success, the size of the file (as returned getSize) is decreased by cnt bytes, or becomes empty if cnt is greater than the previous file size (if cnt is 0, then there is no change, of course). The truncated data (the one beyond the new End-Of-File) is lost. If the file is truncated to the point before the file pointer (i.e. the position is beyond the new EOF), then the file pointer moves to the new End-Of-File (isEOF returns true), otherwise the position (as returned by getPos) doesn't change.
- This function only reduces the file size (as its name suggests). To extend the file simply write data at EOF (see operator<<)
- Even though truncate wouldn't work on an online file, opening such a file in fmOverwrite mode has the same effect as calling truncate(MaxFileSize) after opening a file
- MSys::getFileInfo may return the old file size until the file is closed. getSize, however, always returns the most current size
- Must not be used in global or static scope (i.e. outside of the MAppMain scope)
Let us know
Please Contact us to report any errors on this page, or to suggest any improvements.