Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!uwvax!husc6!Diamond!mlandau From: mlandau@Diamond.UUCP Newsgroups: comp.sys.ibm.pc Subject: Re: Truncating MS-DOS files Message-ID: <4141@diamond.Diamond.BBN.COM> Date: Mon, 16-Feb-87 00:50:57 EST Article-I.D.: diamond.4141 Posted: Mon Feb 16 00:50:57 1987 Date-Received: Mon, 16-Feb-87 19:53:28 EST References: <1987Feb15.123004.21019@gpu.utcs.toronto.edu> Reply-To: mlandau@Diamond.BBN.COM (Matt Landau) Organization: BBN Laboratories, Inc., Cambridge, MA Lines: 20 Summary: write zero bytes and close the file In comp.sys.ibm.pc (<1987Feb15.123004.21019@gpu.utcs.toronto.edu>), lewan@gpu.utcs.toronto.edu (S. Lewandowsky) writes: > >How can I truncate a file using DOS? Once upon a time about a year ago, I spent several days with a debugger tracing what I thought was an errant program which seemed to shorten its own data files inexplicably. In so doing, I discovered an interesting thing: If you seek to a file position, write zero bytes, and close the file, the file is truncated at the seek position. This behavior is consistent in all versions of PC- and MS-DOS from 2.0 to 3.2, but since it is not documented, there's no guarantee it won't go away sometime in the future. Does make it easy to implement truncate() and ftruncate() for the PC, though. -- Matt Landau BBN Laboratories, Inc. mlandau@diamond.bbn.com 10 Moulton Street, Cambridge MA 02238 ...seismo!diamond.bbn.com!mlandau (617) 497-2429