MathGroup Archive 2007

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

Search the Archive

Re: File reading and writing within for loop

  • To: mathgroup at smc.vnet.net
  • Subject: [mg83693] Re: File reading and writing within for loop
  • From: Albert Retey <awnl at arcor.net>
  • Date: Wed, 28 Nov 2007 05:39:28 -0500 (EST)
  • References: <figv8v$g0e$1@smc.vnet.net>

Hi,
> Suppose I have 50 files like following names, in_00.dat,
> in_01.dat, in_02.dat, ........
> I want to read all the files, manipulate and save output like
> out_00.dat, out_01.dat, out_02.dat..... within a "for" loop. Could you
> please suggest how to do these ? If you have answer without "for" loop
> is also OK.
>
Of course there are plenty of possibilities. The following is my first shot:

inputlist = {"in_00.dat", "in_01.dat", "in_02.dat"}

Scan[
  Function[{infile},
   result = docalculationwithfile[infile];
   outfile = StringReplace[infile, StartOfString ~~ "in_" -> "out_"];
   Print[outfile];
   Export[result, outfile, "Table"];
   ],
  inputlist
  ]

Of course you will need to provide a function docalculationwithfile
which does whatever you want to do with one file and you also might need 
a different approach to write the result to the outfile.

hth,

albert


  • Prev by Date: Re: more issues with v.6.0.1
  • Next by Date: Re: Manipulate is sluggish?
  • Previous by thread: Re: File reading and writing within for loop
  • Next by thread: PlotLabel - SubscriptBox - Vers. 6: FontColor not working?