I want to create unique directory for controlling directory’s disk quota. The unique directory name is created as follows:
unique_string()->
base64:encode_to_string(term_to_binary(make_ref())).
But when debuging, the problem appears:
exception exit: {{badmatch,
{error,
" g3IAA2QAFGVtYWNzQHl1cy1pTWFjLmxvY2FsAwAB/ncAAAA8AAAAAA==: No such file or directory.\r\n"}},
The unique_string contains “/”, it caused problems.
I am afraid if just deleting “/”, the feature of unique will lost. How to solve problem?
In addition, is there any other characters can’t be used in directory?
You can replace
base64:encode_to_stringwith ahexifyfunction as follows.You can also tweak this function to allow different set of characters used.
btw, I recommend to do some hashing on the ref to make the names of same length.