Delete chars at the end of a text file
Stewart Gordon
smjg_1998 at yahoo.com
Sat Jan 13 05:09:10 PST 2007
rochus wrote:
<snip>
> void
> trimFile(char[] fileName, int count) {
> // open file
> auto file = cast(char[])std.file.read(fileName);
> // cut of count characters
> file = file[0 .. $-count];
> // write file
> std.file.write(fileName, file);
> }
<snip>
Should work, as long as:
- the file isn't too big to fit in memory and to store in a char[]
- the file contains no multi-byte characters
You can also check out:
- chsize in the C RTL (defined in io.h)
- SetEndOfFile in the Windows API
Stewart.
More information about the Digitalmars-d-learn
mailing list