Let's say I have the code:
$runningLogFile0 = "m0.txt"; $runningLogFile1 = "m1.txt"; $runningLogFile2 = "m2.txt"; If[FileExistsQ[$runningLogFile0], Get[$runningLogFile0], Print["Error: Noexist"];]; If[FileExistsQ[$runningLogFile1], Get[$runningLogFile1], Print["Error: Noexist"];]; If[FileExistsQ[$runningLogFile2], Get[$runningLogFile2], Print["Error: Noexist"];]; that I use to read in a list of consecutively named files, m0.txt,m1.txt, m2.txt. I want to make this code more efficient for reading in a large number of such files, for which it would be very tiresome to do in the above way.
Can I automate this with a Do or Table?
I thought something like
Do["$runningLogFile" <> ToString[i] = "m"<>ToString[i]<>".txt";, {i, 1, 100}]; might work but apparently not.
Do[With[{file = ToExpression["$runningLogFile" <> ToString[k]]}, Set @@ {file, ToString[StringForm["m`1`.txt", k]]}; If[FileExistsQ[file], Get[file], Print["Error: Noexist"]]], {k, 5}]work? $\endgroup$