I have data set in a form ROG1.dat, ROG2.dat,...,ROG100.dat, I want to import all of them in Mathematica, Can you tell me how? Best


Try with:

SetDirectory["path to the directory with the data set"];

fileNames = "ROG" <> ToString@# <> ".dat" & /@ Range[100];

data = Import[#, "Data"] & /@ fileNames;

If in the folder there are just .dat files that you want to import, you can also use (edited after comment below):

data = AssociationMap[Import[#, "Data"] &, FileNames["*.dat"]]
| improve this answer | |
  • 1
    $\begingroup$ FileNames accepts glob operators for filenames, e.g. FileNames["*.dat"], so Select is superfluous. Also, using FileNames like that will cause them to be listed in lexicographical order, e.g. In[90]:= FileNames["*.dat"] (*Out[90]= {"ROG10.dat", "ROG1.dat", "ROG20.dat", "ROG2.dat"}*) . If you're running at least v10, I'd suggest using AssociationMap instead of Map, then you can re-order at will. $\endgroup$ – rcollyer Aug 13 '18 at 19:47
  • 1
    $\begingroup$ Thanks for that! I fixed the FileNames[] command in my post according to your suggestion :) $\endgroup$ – Fraccalo Aug 13 '18 at 20:42
  • $\begingroup$ You're welcome. You already have my +1. :) $\endgroup$ – rcollyer Aug 13 '18 at 21:07

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