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
1 Answer
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"]]
-
1$\begingroup$
FileNames
accepts glob operators for filenames, e.g.FileNames["*.dat"]
, soSelect
is superfluous. Also, usingFileNames
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 usingAssociationMap
instead ofMap
, then you can re-order at will. $\endgroup$– rcollyerAug 13, 2018 at 19:47 -
1$\begingroup$ Thanks for that! I fixed the FileNames[] command in my post according to your suggestion :) $\endgroup$– FraccaloAug 13, 2018 at 20:42
-
$\begingroup$ You're welcome. You already have my +1. :) $\endgroup$– rcollyerAug 13, 2018 at 21:07