Truncate a file: Difference between revisions
Content added Content deleted
m (minor grammatical fixes) |
No edit summary |
||
Line 146: | Line 146: | ||
<lang ocaml>val ftruncate : file_descr -> int -> unit |
<lang ocaml>val ftruncate : file_descr -> int -> unit |
||
(** Truncates the file corresponding to the given descriptor to the given size. *)</lang> |
(** Truncates the file corresponding to the given descriptor to the given size. *)</lang> |
||
=={{header|Liberty BASIC}}== |
|||
Note Liberty BASIC provides a way to exit a function. |
|||
<br> |
|||
It is also possible to call API functions to achieve this task. |
|||
<lang lb> |
|||
dim info$( 50, 50) ' NB pre-dimension before calling file-exists |
|||
' needed for file-exists function |
|||
open "test.dat" for output as #1 'create file |
|||
for i = 1 to 10000 |
|||
#1 chr$( int( 256 *rnd( 1))); |
|||
next |
|||
close #1 |
|||
call truncateFile, "test.dat", 5000 |
|||
wait |
|||
sub truncateFile fn$, length |
|||
if fileExists( DefaultDir$, fn$) =0 then notice "No such file": exit sub |
|||
open fn$ for input as #i |
|||
file$ =input$( #i, lof( #i)) |
|||
if len( file$) <length then notice "Too short": close #i: exit sub |
|||
file$ =left$( file$, length) |
|||
close #i |
|||
open "test.dat" for output as #o |
|||
#o file$ |
|||
close #o |
|||
end sub |
|||
function fileExists( path$, filename$) |
|||
files path$, filename$, info$() |
|||
fileExists =val( info$( 0, 0)) 'non zero is true |
|||
end function |
|||
end |
|||
</lang> |
|||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |