MathGroup Archive 2004

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

Search the Archive

Re: padding numbers in front of uniquely generatd names

  • To: mathgroup at smc.vnet.net
  • Subject: [mg48313] Re: padding numbers in front of uniquely generatd names
  • From: "Peter Pein" <petsie at arcor.de>
  • Date: Sun, 23 May 2004 06:15:39 -0400 (EDT)
  • References: <c8kd3j$mri$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

"sean kim" <sean_incali at yahoo.com> schrieb im Newsbeitrag
news:c8kd3j$mri$1 at smc.vnet.net...
> hello group.
>
> below will do exactly what it';s supposed to do which is generate
> unique file names.
>
>
> StringJoin[Unique["plot"] // ToString, ".jpg"]
>
>
> I wanted to pad 0's in front of my file names for the purpose of
> sorting them in a folder by their names. without the 0's in front they
> don't sort right.
>
> i found this in the archive that does sort of what i want to...
>
> With[{i = 1}, "data-" <> ToString[PaddedForm[i, 3, NumberPadding
> ->{"0", "0"}]] ]
>
> or
>
> Table["data-" <> ToString[ PaddedForm[i, 3, NumberPadding -> "0"]],
> {i, 0, 20}]
>
>
> above work fine for making the names upfront then assigning them to
> pictures, but what if i wanted to generate them as the algorythm runs.
> now i thought this was gonna do it...
>
>
> StringJoin[ToString[ PaddedForm[ Unique["plot"], NumberPadding ->
> {"0", "0"}]], ".jpg"]
>
> but no, above is exactly the same as what I had before.
>
> Without using Table, or With, how do i change it so that above will
> generate unique names with 0's padded?
>
> any thoughts will be most appreciated.
>
> thanks in advance
>
> sean
>

Hi Sean,
I do not understand, why it is impossible to increment a  variable -
say plotnr - each time you want to save a plot, while your algorithm runs?

plotnr=0;
...some calculations...
plot=Plot[...];
Export["mywonderfulplot-" <>
  ToString[PaddedForm[++plotnr, 3, NumberPadding->{"0", "0"}]]<>
  ".jpg",plot, "JPG"];
...go on with program...

But since this doesnt work in your algorithm, you can use Unique:
Suppose you want filenames of the form plotXYZ.jpg. Then

StringInsert[#, StringTake["00", 3 - (StringLength[#] - 4)], 5] &
    [ToString[Unique["plot"]]] <> ".jpg"

will do the job if Unique doesn't generate symbols with more than 3 digits.
So it would be a good idea to do a Remove["plot*"] when starting a new job.

-- 
Peter Pein, Berlin
to write to me, start the subject with [




  • Prev by Date: Re: Compile
  • Next by Date: Re: Eigensystem: different solution in V5.0 and V4.1 ??
  • Previous by thread: Re: padding numbers in front of uniquely generatd names
  • Next by thread: SetPrecision - What does in find?