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

  • $\begingroup$ Import[#, "Table"] & /@ Table["xcode" <> IntegerString[i, 10] <> ".data", {i, 1, 10}] $\endgroup$ – user1066 Jul 1 '18 at 12:37

You can create the list of filenames using StringTemplate

 , {k, 5}
(* {"FileNameBase1.extension", "FileNameBase2.extension", \
"FileNameBase3.extension", "FileNameBase4.extension", \
"FileNameBase5.extension"} *)

Now we apply this to your case

alldata = Table[
   , "Table"]
  , {k, {1,4,7,10}}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.