Quite simply, how do I remove x amount of bytes, or a string from (the end of) a file..? I know how to append bytes — I need to do the opposite.
Unfortunately I haven't found any examples of how to do this :-/
NSFileHandle* fh = [NSFileHandle fileHandleForUpdatingAtPath: path];
[fh seekToEndOfFile];
??
NSFileHandle
has a truncateFileAtOffset
method that does exactly what you want.
Given the NSString sFilePath variable is set, this is how you could truncate the file to 0 bytes:
NSFileHandle *hFile;
hFile = [NSFileHandle fileHandleForUpdatingAtPath:sFilePath];
[hFile truncateFileAtOffset: 0];
[hFile closeFile];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With