I can run this with no problem:
Import[NotebookDirectory[] <> "a10.mx"];
Instead of that, I want to describe 10 with a variable as k,
k = 10;
Import[NotebookDirectory[] <> StringForm["a``.mx", k]];
which does not work.
First, I'd recommend FileNameJoin[] as a system-independent way to generate a pathname for a file.
Next, another alternative for constructing the filename is StringTemplate[], which is used here and in many other Q&As:
FileNameJoin[{NotebookDirectory[], StringTemplate["a`1`.mx"][k]}]
or you may want template
(* Define your variable *)
k = 10;
(* Construct the filename string using StringTemplate *)
fileName = StringTemplate["a`k`.mx"][<|"k" -> k|>];
(* Construct the full path *)
filePath = NotebookDirectory[] <> fileName;
(* Import the file *)
Import[filePath]
StringFormis that is doesn't return a String. It looks like it does but it isn't. You can check using theHeadcommand. $\endgroup$