RosettaCodeData/Task/Truncate-a-file/PowerBASIC/truncate-a-file.basic

18 lines
406 B
Plaintext

SUB truncateFile (file AS STRING, length AS DWORD)
IF LEN(DIR$(file)) THEN
DIM f AS LONG
f = FREEFILE
OPEN file FOR BINARY AS f
IF length > LOF(f) THEN
CLOSE f
ERROR 62 'Input past end
ELSE
SEEK f, length + 1
SETEOF f
CLOSE f
END IF
ELSE
ERROR 53 'File not found
END IF
END SUB