I have a folder of 457 .dpt files, which I would like to import in to Mathematica, extract the second column, and combine all 457 into one array, to then save as a .xlsx file. I just can't get the loop right, I've tried For and Do. Also I get the impression that Mathematica isn't great at appending columns so I tried to append them as rows then transpose at the end.
Can anyone help? Thanks.
Clear["Global'*"];
SetDirectory["C:\\Users\\...blahblah...\\TPP 13 Dec 17 (DPT Files)"];
files = FileNames[]; (*gives a list of the 457 filenames*)
out={};
For[i = 0, i < 457, i++,
data = Import[files[[i]]]
col = data[[All, 2]] (*Extracts second column*)
AppendTo[out, {col}]
]
outputfile=Transpose[out]
Export["allthedatainonefile.xlsx",outputfile]
Table. You could doout = Table[ Import[ file][[All,2]], {file, files}]– Jason B. Dec 14 '17 at 15:03Map:Export["path",Import[#][[All,2]]&/@files];– george2079 Dec 14 '17 at 15:49Forloop, and appending to a list at each step, there is usually a better, more Mathematica way to do it. I included a longer version which is commented out. – Jason B. Dec 14 '17 at 17:01files=line. (Except I forgot to transpose, soExport["path",Transpose[Import[#][[All,2]]&/@files]];) – george2079 Dec 14 '17 at 18:40