Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Importing (and dealing with) multiple files

  • To: mathgroup at
  • Subject: [mg60793] Re: Importing (and dealing with) multiple files
  • From: Torsten Coym <torsten.coym at>
  • Date: Thu, 29 Sep 2005 05:40:59 -0400 (EDT)
  • Organization: Fraunhofer Gesellschaft (
  • References: <dhdbdh$8f3$>
  • Sender: owner-wri-mathgroup at


create a list of all matching file names:

files = FileNames["*ASC"]

Then take a look at Map[] or /@.
Mathematica is a much more functional than imperative programming
language. There is usually no need  for For[]-loops.

filecontents = (Import[#1, "Table"] & ) /@ files;
croppedcorrelations = (Take[#1, {1, 2}] & ) /@

statistics = NonlinearRegress[#,

so long,

contact at wrote:
> Hello all,
> I have experimental data that is stored in a number of files.  I've
> been importing the files (as tables) into Mathematica one-by-one, and
> working on them like so:
> rawdata=Import["C:\\filename.ASC", "Table"];
> croppedcorrelation=Take[rawdata,{75,185}];
> statistics=NonlinearRegress[croppedcorrelation, math_here...]
> then painstakingly picking out the relevant statistical parameter from
> each file, collecting them all, and later plotting them.  What I'd
> really like to do is import an entire directory's worth of these files
> (each file is a different time point), do the same statistical thing to
> each file, save the relevant parameters from each file in a table form
> and then plot the whole shebang.
> One of the problems is that I don't know ahead of time how many .ASC
> files are in the directory, so I need to set up the For loop (or
> whatever structure) to account for that.  I tried using FileNames[] to
> get the list of files, assigning them to an array, then using Import[]
> on each of those array elements.  It didn't work.
> Does anyone have any suggestions?
> Thanks!
> Dan

  • Prev by Date: Re: Re: Checking for a given phrase in an expression
  • Next by Date: Re: Processing graphics from C programme with MathLink
  • Previous by thread: Re: Importing (and dealing with) multiple files
  • Next by thread: Re: Importing (and dealing with) multiple files