program convcase; uses crt,dos; const TYPE1 = true; {true changes to lowercase and false changes to uppercase} function file_exists(filename : string) : boolean; var tmpfile : text; begin file_exists := false; assign(tmpfile,filename); {$I-} reset(tmpfile); {$I+} if IOResult = 0 then begin file_exists := true; close(tmpfile); end; end; procedure type_filename(var textfile : text; var path : string); var filename : string; ch : char; ok : boolean; rnd : integer; begin textcolor(black); clrscr; repeat ok := false; gotoxy(30,9); textcolor(5); write('Convert case program'); gotoxy(24,10); textcolor(1); write('Type end and press Return to exit'); textcolor(6); gotoxy(1,13); write('Please type filename and path : '); textcolor(4); readln(path); { if filename = '' then begin rnd := random(3); case rnd of 0 : filename := 'fm2000\fm2000.pas'; 1 : filename := 'batty\batty.pas'; end; end;} if path = 'end' then begin textcolor(lightgray); clrscr; halt; end; if file_exists(path) then begin assign(textfile,path); reset(textfile); ok := true; end else begin textcolor(7); gotoxy(33,16); write('There''s no file'); textcolor(black); ch := readkey; gotoxy(33,13); clreol; gotoxy(33,16); clreol; end; until ok; textcolor(black); clrscr; end; procedure convert_case1(var textfile,results : text); var line : string; i : integer; tmpchar : char; begin while not eof(textfile) do begin readln(textfile,line); for i := 1 to 256 do begin tmpchar := line[i]; if TYPE1 then begin if tmpchar in ['A'..'Z'] then {change to lowercase} inc(tmpchar,32); end else begin if tmpchar in ['a'..'z'] then {change to uppercase} dec(tmpchar,32); end; line[i] := tmpchar; end; writeln(results,line); end; end; var textfile : text; results : text; path : string; P : PathStr; D : DirStr; N : NameStr; E : ExtStr; begin textmode(80); type_filename(textfile,path); {this is used to save the file in the save folder as the source file} P := path; Fsplit(P,D,N,E); E := '.txt'; {saves file with .txt extension} P := D+N+E; textcolor(black); clrscr; textcolor(5); assign(results,P); {$I-} rewrite(results); {$I+} if IOResult <> 0 then begin writeln('Error saving file'); readln; textcolor(lightgray); clrscr; halt; end else begin writeln('File saved at '+P); readln; end; convert_case1(textfile,results); close(results); close(textfile); end.