RosettaCodeData/Task/Truncate-a-file/Liberty-BASIC/truncate-a-file.basic
2023-07-01 13:44:08 -04:00

30 lines
821 B
Text

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