Mega Code Archive

 
Categories / Delphi / Examples
 

Fileextnchange

function TEditorForm.ChangeFileExtension(oldName, newExtn: String): String; var tempArray: array[0..maxFileNameLength] of Char; tempString: String; nameLength, nexExtnLength, i, j, dotPos: Integer; dotPresent: Boolean; begin dotPresent := True; nameLength := Length(oldName); nexExtnLength := Length(newExtn); for i := 1 to nameLength do begin tempArray[i - 1] := oldName[i]; end; j := 0; while not(tempArray[j] = '.') do begin Inc(j); if (j >= maxFileNameLength) then begin dotPresent := False; break; end; end; dotPos := (j + 1); j := 1; if (dotPresent = True) then begin for i := dotPos to (dotPos + nexExtnLength) do begin tempArray[i] := newExtn[j]; Inc(j); end; tempArray[i + 1] := #0; Result := String(tempArray); end else Result := oldName + newExtn; end;