If you only need filenames, but do not need them to be "human readable", then you could take advantage of \pdfstringdef
\documentclass{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[unicode]{hyperref} \makeatletter \begingroup \catcode`| 0 \catcode`\\ 12 |gdef|makestring@i\#1#2#3#4% {#1#2#3|if|relax#4|expandafter|@gobbletwo|fi|makestring@i#4} |endgroup \newcommand*{\makestring}[2]{% \pdfstringdef\makestring@{#2}% \edef#1{\expandafter\makestring@i\makestring@\relax}% } \makeatother \begin{document} \makestring{\foo}{æüßéñ} \texttt{\meaning\foo} \end{document} A variation on this theme which is much more efficient, it show the utf8 bytes. One could produce in hexadecimal if desired. (in fact there are possibly macros in utf8.def which could be used here)
\documentclass{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \makeatletter \newcommand*\MakeString[2]{% \begingroup \def\UTFviii@two@octets##1##2{\the\numexpr`##1\relax\the\numexpr`##2}% \def\UTFviii@three@octets##1##2##3{\the\numexpr`##1\relax\the\numexpr`##2\relax\the\numexpr`##3\relax}% \def\UTFviii@four@octets##1##2##3##4{\the\numexpr`##1\relax\the\numexpr`##2\relax\the\numexpr`##3\relax\the\numexpr`##4\relax}% \xdef#1{#2}% \endgroup } \makeatother \begin{document} \MakeString{\foo}{æüßéñ} \texttt{\meaning\foo} \show\foo \end{document} Produces:
> \foo=macro: ->195166195188195159195169195177. l.23 \show\foo (I should improve so that each byte produce a three-digits decimal, here leading zeros are stripped, here it is, but I used xintbinhex by laziness)
\documentclass{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{xintbinhex} \makeatletter \newcommand*\MakeString[2]{% \begingroup \def\UTFviii@two@octets##1##2{\xintDecToHex{\the\numexpr`##1\relax}\xintDecToHex{\the\numexpr`##2\relax}}% \def\UTFviii@three@octets##1##2##3{\xintDecToHex{\the\numexpr`##1\relax}\xintDecToHex{\the\numexpr`##2\relax}\xintDecToHex{\the\numexpr`##3\relax}}% \def\UTFviii@four@octets##1##2##3##4{\xintDecToHex{\the\numexpr`##1\relax}\xintDecToHex{\the\numexpr`##2\relax}\xintDecToHex{\the\numexpr`##3\relax}\xintDecToHex{\the\numexpr`##4\relax}}% \xdef#1{#2}% \endgroup } \makeatother \begin{document} \MakeString{\foo}{æüßéñ} \texttt{\meaning\foo} \show\foo \end{document} produces in log
> \foo=macro: ->C3A6C3BCC39FC3A9C3B1. l.25 \show\foo 