Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
36
Task/Truncate-a-file/Pascal/truncate-a-file.pas
Normal file
36
Task/Truncate-a-file/Pascal/truncate-a-file.pas
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
Program FileTruncate;
|
||||
|
||||
uses
|
||||
SysUtils;
|
||||
|
||||
var
|
||||
myfile: file of byte;
|
||||
filename: string;
|
||||
position: integer;
|
||||
|
||||
begin
|
||||
write('File for truncation: ');
|
||||
readln(filename);
|
||||
if not FileExists(filename) then
|
||||
begin
|
||||
writeln('Error: File does not exist.');
|
||||
exit;
|
||||
end;
|
||||
|
||||
write('Truncate position: ');
|
||||
readln(position);
|
||||
|
||||
Assign(myfile, filename);
|
||||
Reset(myfile);
|
||||
if FileSize(myfile) < position then
|
||||
begin
|
||||
writeln('Warning: The file "', filename, '" is too short. No need to truncate at position ', position);
|
||||
Close(myfile);
|
||||
exit;
|
||||
end;
|
||||
|
||||
Seek(myfile, position);
|
||||
Truncate(myfile);
|
||||
Close(myfile);
|
||||
writeln('File "', filename, '" truncated at position ', position, '.');
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue