Wolfram Mathematica imports data from multiple files

I have a lot of files. Each of them contains data. I can gladly import one file into Mathematica. But there are over 500 hundred files. I do it like this:

 Import["~/math/third_ks/mixed_matrices/1.dat", "Table"];
 aaaa = %
  (*OUTPUT  - some data, I can access them!*)

All I want to do is just create a circle (I can do this), but I can’t change the file name - 1.dat. I want to change it.

I tried to make such a decision. I created part of the possible names, and I wrote them in a separate file.

Import["~/math/third_ks/mixed_matrices/generate_name_of_files.dat", "Table"];
aaaa = %

Output: {{"~/math/third_ks/mixed_matrices/0.dat"}, \
          {"~/math/third_ks/mixed_matrices/1.dat"}, ......

All I want to do is Table[a=Import[aaaa[[i]] ,{i,1,500}]

But the function Importaccepts only String"" objects as the file / path name.

+3
source share
3 answers

FileNames , , .

Import .

data , .

data = Import[#,"Table"]& /@ FileNames["~/math/third_ks/mixed_matrices/*.dat"];
+4

, . , , , Flatten , String, Import. n * 1, List, a String, String s.

, Map (/@) Table .

+2

Thanks for your reply.
It so happened that I got two solutions at the same time. I think it would be unfair to forget about the second way.

    aaaa = "~/math/third_ks/mixed_matrices/" <> ToString[#] <> ".dat" & /@  Range[0, 116];
   (*This thing generates list of lines  
     Output:
       {"~/math/third_ks/mixed_matrices/0.dat", \
        "~/math/third_ks/mixed_matrices/1.dat", \
        "~/math/third_ks/mixed_matrices/2.dat",    .....etc, until 116

    Table[Import[aaaa[[i]], "Table"], {i, 1, 117}];
    (*and it just imports data from file*)

    bbbb = %;  (*here we have all data, voila!*)

By the way, this is not my decision. This was suggested by one of my friends: https://stackoverflow.com/users/1243244/light-keeper

0
source

All Articles