2

I'm trying to import many files which have the same name "x.data", but they end with a extension "x_code1.data".

I was trying to import all files with the routine:

Importdata1 = 
Import["x_code1.dat", "Table"];

But I want to have an array with all the codes, something similar to:

For i = {1,4,7,10}

Importalldata[i] = 
Import["x_code[i].dat", "Table"];

How can I achieve this?

Thank you so much

1 Answers1

3

You can create the list of filenames using StringTemplate

Table[
 StringTemplate["FileNameBase``.extension"][k]
 , {k, 5}
 ]
(* {"FileNameBase1.extension", "FileNameBase2.extension", \
"FileNameBase3.extension", "FileNameBase4.extension", \
"FileNameBase5.extension"} *)

Now we apply this to your case

alldata = Table[
  Import[
   StringTemplate["x_code``.dat"][k]
   , "Table"]
  , {k, {1,4,7,10}}
  ]
rhermans
  • 36,518
  • 4
  • 57
  • 149