# variables in filename

I have some scv files, they are named based on the testing condition from the simulation runs, basically from blk50_25 to blk300_150, the first number after "blk" was ranged from 50 to 300 incremented by 10, and 2nd number after "_" was ranged from 25 to 150 incremented by 5. (i.e first file blk50_25, 2nd file blk60_30, 3rd file blk70_35, etc.) I'm trying to write a loop to call all the files and do an x-y plot of each, here's what I have done

data = Import["/Users/Desktop/ConvTestOP/blk50_25.csv", "CSV"]
MD = Table[{data[[j, 1]], data[[j, 2]]}, {j, 1, Length[data]}];
Reverse /@ MD
ListPlot[MD[[All, {2, 1}]]]


I'm not sure how to put variables in the filename, much appreciated if anyone can give me a hint.

For old versions:

Table[ToString[StringForm["/Users/Desktop/ConvTestOP/blk1_2.csv",
10 k + 50, 5 k + 25]], {k, 0, 25}]


For new versions:

Table[StringTemplate["/Users/Desktop/ConvTestOP/blki_j.csv"] @
<|"i" -> 10 k + 50, "j" -> 5 k + 25|>, {k, 0, 25}]


Both generate a list of the filenames following your system; modify the Table[] as needed (e.g. incorporating Import[] and ListPlot[]).

• Thanks for the speed response, when I name the data, is there a way to do something like data_i_j = Import["/Users/Desktop/ConvTestOP/blki_j.csv", "CSV"] where i and j are based on your code above? – Gvxfjørt Oct 4 '16 at 3:14
• @Gavy, you can do something like Table[data[10 k + 50, 5 k + 25] = (* stuff *)] for that, and then refer to data[50, 25], data[60, 30], etc. – J. M. is in limbo Oct 4 '16 at 3:26

Alternatively, you can grab all the file names of the appropriate type and read them in. This means you don't need to know the exact names of the files in advance.

allfiles = FileNames["*", "/Users/Desktop/ConvTestOP/"];
allData = Import[#] & /@ allfiles;


then build your plots directly from allData.