Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!seismo!nbires!hao!gaia!zhahai From: zhahai@gaia.UUCP Newsgroups: comp.sys.ibm.pc Subject: Re: Truncating MS-DOS files Message-ID: <286@gaia.UUCP> Date: Tue, 17-Feb-87 13:52:31 EST Article-I.D.: gaia.286 Posted: Tue Feb 17 13:52:31 1987 Date-Received: Thu, 19-Feb-87 06:12:18 EST References: <1987Feb15.123004.21019@gpu.utcs.toronto.edu> Reply-To: zhahai@gaia.UUCP (Zhahai Stewart) Organization: Gaia Corp., Boulder, CO Lines: 22 Summary: 0 byte write truncates, documentation pages 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 Writing 0 bytes (ie: CX = 0 when doing the write) will do this. I think it works for all DOS 2.X and above. Due to MS DOS's 2 parents (CP/M and UN*X) there are two sets of file i/o functions (one based on each). For function 28 (hex) "Random Block Write" this is documented pn page 5-28 of the DOS 2.1 tech ref manual, and page 6-85 for the DOS 3.1 tech ref manual. For function 40 (hex) it is described on page 6-126 of the DOS 3.1 tech ref, but is not mentioned in the older DOS 2.1 tech ref manual. Others can tell us if these functions are documented differently for DOS 2.0, 3.0, 3.2, etc - these are the only tech ref manuals I have. I hope this helps. ~z~ -- Zhahai Stewart {hao | nbires}!gaia!zhahai