Re: Question about filenames for Export[...]
- To: mathgroup at smc.vnet.net
- Subject: [mg99756] Re: Question about filenames for Export[...]
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Wed, 13 May 2009 05:08:28 -0400 (EDT)
On 5/12/09 at 5:44 AM, fdsa at ff.gr (Lorents) wrote: >Hello, I'm using Mathematica 6. I'd like to know how to define a >file name (to be later used in Export) so that the file name >contains the value of an index variable i. To exemplify, in Fortran >this task would be accomplished by something like: >character(len) :: FileName ... write(FileName,'(A,I4.4)') 'MyName',i >These lines would produce filenames which, for i=1,2,... are >MyName0001, MyName0002, ... >Is there any neat way of doing the same with Mathematica? Creating a list of indexed strings can be done as follows: In[1]:= "file" <> ToString[NumberForm[#, 4, NumberPadding -> {"0", "0"}]] & /@ Range[5] Out[1]= {file00001,file00002,file00003,file00004,file00005} Or if I wanted to export a list of things to a set of indexed files I would do MapIndexed[ Export["file" <> ToString[NumberForm[#2[[1]], 4, NumberPadding -> {"0", "0"}]], #1, "Table"] &, data] Here, data is assumed to be a list of the things to export and is assumed to be less than 10000 items.