Magnetic shape memory effect in thin foils