Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!mit-eddie!genrad!decvax!tektronix!reed!psu-cs!omepd!perry From: perry@omepd.UUCP Newsgroups: comp.sys.ibm.pc Subject: Re: Truncating MS-DOS files Message-ID: <419@omepd> Date: Thu, 19-Feb-87 02:18:31 EST Article-I.D.: omepd.419 Posted: Thu Feb 19 02:18:31 1987 Date-Received: Fri, 20-Feb-87 07:18:09 EST References: <1987Feb15.123004.21019@gpu.utcs.toronto.edu> Sender: news@omepd Reply-To: perry@inteloa.intel.com (Perry The Cynic) Organization: Intel Corp., Hillsboro Lines: 40 Keywords: truncating files Summary: how to do it In article <1987Feb15.123004.21019@gpu.utcs.toronto.edu> lewan@gpu.utcs.toronto.edu (S. Lewandowsky) writes: >How can I truncate a file using DOS? For example, I may open a >file, write to it and read from it extensively, and as a result its size >--when I use the close file handle call--would be about 120K or greater. >However, I only want to save the first 10K of that file, so I'd like to >place the file pointer to whereever I want the file to end, and then >truncate it so that the information beyond the pointer is discarded >and the file size is reduced to 10K. >There is a truncate procedure in Turbo Pascal, so there must be a way >of doing it--but how do I do it in an ASM program using INT 21H? Fresh from the MSDOS Programmer's Reference Manual: Both the `random block write' (28H) and the `write handle' (40H) functions of MSDOS process a special case: If you specify a write length of zero (i.e., CX=0), the file length is set. The FCB function (28H) sets the length to the `relative record' field in the FCB, while the handle operation (40H) uses the current file pointer. In both cases, the result is either a lengthening or a truncation. Commercial Time: Allow me to point out once more that the MSDOS PROGRAMMER'S REFERENCE MANUAL contains BY DEFINITION all the official answers to the programming interface of MSDOS. If it isn't in there, it isn't official. This manual also includes a set of migration rules (i.e., what features to avoid) that might give your programs a MUCH brighter future. Of course, IBM has its own `official' definition of MS- pardon PCDOS. But I think they have mainly tinkered with the internals, not the interface. I wouldn't know for sure, I don't buy anything from IBM... Disclaimer: No relation to Microsoft, except as a (sometimes frustrated) user. ------------------------------------------------------------------------ << Perry The Cynic >> ...!tektronix!ogcvax!omepd!inteloa!perry ...!verdix!omepd!inteloa!perry (Peter Kiehtreiber) -or try- perry@inteloa.intel.com