MathGroup Archive 2007

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

Search the Archive

RE: change filename automatically in Export Command

  • To: mathgroup at smc.vnet.net
  • Subject: [mg73843] RE: [mg73829] change filename automatically in Export Command
  • From: "David Annetts" <davidannetts at aapt.net.au>
  • Date: Fri, 2 Mar 2007 06:21:49 -0500 (EST)
  • References: <200703011121.GAA28358@smc.vnet.net>

Hi serdal 

> Does anybody know how to change the name of the file with a 
> Do loop in the = Export comand For example I want to name my 
> files as a1.png a2.png a3.png ....a1000.png each time I use 
> the following command Export["filename",aa1,"PNG"]
> 
> i need to change filename by hand is there a way of doing it 
> automatically=

This question gets asked a few times a year so I'm surprised that a search
of the Group's archives didn't turn up one or two (dozen) solutions.  In any
case ....

What you need to do is combine the commands ToString and StringJoin.

If you insist on using a Do loop, then something like 

	Do[
	  ofile = StringJoin["a", ToString[ji], ".png"];
	  Export[ofile, -Graphics-, "PNG"],
	  {ji, 10}
	  ]

Will work.

Otherwise, you can use 

	ofile = ("a" <> ToString[#] <> ".png") & /@ Range[10]

Which is equivalent to 

	ofile = StringJoin["a", ToString[#], ".png"] & /@ Range[10]

And end up with something more (IMHO) useful in about 1/5 of the time.  It's
more useful since you end up with a list that you can combine with other
functional commands.  More readable too.

Regards,

Dave.


  • Prev by Date: Re: Sort with -Infinity fails
  • Next by Date: Re: Sort with -Infinity fails
  • Previous by thread: change filename automatically in Export Command
  • Next by thread: change filename automatically in Export Command