FileResize

版本 1.0.0.0 (8.7 KB) 作者: Jan
Expand and truncate existing files - efficient C-Mex
308.0 次下载
更新时间 2012/7/3

查看许可证

FileResize

While expanding a file by appending zeros is easy in Matlab, truncating is much harder: Create a new file, copy the contents of the original file until the wanted position, delete original file, rename the new file. For large files this is rather inefficient.

This C-Mex function can expand or truncate a file directly. For expanding it is twice as fast as using FWRITE to append zeros, and the speedup for truncating files grows fast with the file length.

[Status, Msg] = FileResize(File, Bytes, Mode)
INPUT:
File: File name, Unicode and UNC paths accepted.
Bytes: Number of bytes.
Mode: 'set': Absolute size, this is the default.
'move': Relative to the end, truncate if [Bytes] is negative.

OUTPUT:
Status: Scalar DOUBLE, 0 on success, otherwise < 0.
Msg: Explanations of problems.

This function must be compiled before it can be used, or download a pre-compiled file:
http://www.n-simon.de/mex

Tested: Matlab 6.5, 7.7, 7.8, 7.13, WinXP/32, Win7/64
Compiler: LCC3.8, BCC5.5, OWC1.8, MSVC2008/2010
Assumed Compatibility: higher Matlab versions, Linux and MacOS.
Run the unit-test function uTest_FileResize to check validity and speed.

Bugreports and suggestions for improvements are welcome.

引用格式

Jan (2024). FileResize (https://www.mathworks.com/matlabcentral/fileexchange/37384-fileresize), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2011b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 File Name Construction 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0.0.0