Re: File reading and writing within for loop
- To: mathgroup at smc.vnet.net
- Subject: [mg83676] Re: File reading and writing within for loop
- From: Szabolcs Horvát <szhorvat at gmail.com>
- Date: Wed, 28 Nov 2007 05:29:31 -0500 (EST)
- References: <figv8v$g0e$1@smc.vnet.net>
nilaakash at gmail.com wrote: > 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. > > Thanks in advance. > With regards. > nilaakash > The looping construct in Mathematica corresponding to the "for" of other languages is called Do[]. You could use Do[ Module[{suffix, data}, suffix = StringJoin @@ ToString /@ IntegerDigits[i, 10, 2]; data = Import["in_" <> suffix <> ".dat", "WhateverFormatYouNeed"]; Export["out_" <> suffix <> ".dat", process[data], "WhateverFormatYouNeed"] ], {i, 0, 49}] -- Szabolcs