detect filename encoding all together

Do this to avoid wrong detection if filename is not long enough.
Assume filenames' encoding are same.