Adapted heftig's encdir patch. Closes #2468.

We don't set @encdir so 'unless @encdir' is superfluous.