Saturday, 25 May 2013

Delete a part in a file without ruining the encoding and extension

Delete a part in a file without ruining the encoding and extension

I have a fairly large database of files. The files have very different extensions (.txt, .doc, .ppt etc), but every one of them has a certain phrase at the start of the file which has to be removed.
So, let's say I have a file randomtext.doc. Looking at the file in a simple text editor, the file would normally begin with:
\D0\CF ࡱ\E1\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00>\00 \00\FE\FF                           \00 \00\00\00\00\00\00\00\00\00\00\00 \00\00\00K\00\00\00\00\00\00\00\00 \00\00M\00\00\00 \00\00\00\FE\FF\FF\FF\00\00\00\00J\00\00\00\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\
But my file begins with:
MYPHRASE \D0\CF ࡱ\E1\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00>\00 \00\FE\FF  \00 \00\00\00\00\00\00\00\00\00\00\00 \00\00\00K\00\00\00\00\00\00\00\00 \00\00M\00\00\00 \00\00\00\FE\FF\FF\FF\00\00\00\00J\00\00\00\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\
Deleting the phrase in a regular text editor ruins the file (for example, this file, which would normally be a .doc file, wouldn't be able to be viewed by Microsoft Word). I need to be able to delete the phrase, but keep the file extension etc.

No comments:

Post a Comment