| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
| 2 |
"http://www.w3.org/TR/html4/strict.dtd"> |
| 3 |
<html> |
| 4 |
<head> |
| 5 |
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
| 6 |
<title>filetruncate</title> |
| 7 |
<meta http-equiv="Content-Style-Type" content="text/css"> |
| 8 |
<link rel="stylesheet" href="../../style.css" type="text/css"> |
| 9 |
</head> |
| 10 |
|
| 11 |
<body> |
| 12 |
|
| 13 |
|
| 14 |
<h1>filetruncate</h1> |
| 15 |
|
| 16 |
<p> |
| 17 |
Changes the size of a file. <em>(version 4.67 or later)</em> |
| 18 |
</p> |
| 19 |
|
| 20 |
<pre class="macro-syntax"> |
| 21 |
filetruncate <filename> <size> |
| 22 |
</pre> |
| 23 |
|
| 24 |
<h2>Remarks</h2> |
| 25 |
|
| 26 |
<p> |
| 27 |
Changes the <size> bytes of a <filename> file.<br> |
| 28 |
Null characters('\0') are appended if the file is extended.<br> |
| 29 |
</p> |
| 30 |
|
| 31 |
<p> |
| 32 |
The system variable "result" value is set to 0 if the file size is successfully changed. |
| 33 |
The system variable "result" value of -1 indicates an error. |
| 34 |
</p> |
| 35 |
|
| 36 |
<h2>Example</h2> |
| 37 |
|
| 38 |
<pre class="macro-example"> |
| 39 |
; Changes 32 bytes of a file. |
| 40 |
filetruncate 'test.exe' 32 |
| 41 |
if result = -1 then |
| 42 |
messagebox 'file truncate error' 'filetruncate' |
| 43 |
else |
| 44 |
messagebox 'file truncate success' 'filetruncate' |
| 45 |
endif |
| 46 |
</pre> |
| 47 |
|
| 48 |
<pre class="macro-example"> |
| 49 |
; Makes 8M bytes of a file containing all zero data. |
| 50 |
size = 8*1024*1024 |
| 51 |
filetruncate 'bigfile.bin' size |
| 52 |
</pre> |
| 53 |
|
| 54 |
<pre class="macro-example"> |
| 55 |
; Opens a log file at the macro file directory. |
| 56 |
getdir dir |
| 57 |
sprintf2 filename '%s\test.log' dir |
| 58 |
logopen filename 0 0 |
| 59 |
; Limitation of a file size |
| 60 |
maxsize = 512 |
| 61 |
counter = 0 |
| 62 |
|
| 63 |
:loop |
| 64 |
counter = counter + 1 |
| 65 |
sprintf2 line 'counter = %d' counter |
| 66 |
logwrite line |
| 67 |
logwrite #13#10 |
| 68 |
filetruncate filename maxsize |
| 69 |
if result = -1 then |
| 70 |
messagebox 'file truncate error' 'filetruncate' |
| 71 |
goto skip |
| 72 |
endif |
| 73 |
if counter > 32 goto skip |
| 74 |
goto loop |
| 75 |
|
| 76 |
:skip |
| 77 |
logclose |
| 78 |
</pre> |
| 79 |
|
| 80 |
</body> |
| 81 |
</html> |