Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: padding numbers in front of uniquely generatd names

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

"sean kim" <sean_incali at> schrieb im Newsbeitrag
news:c8kd3j$mri$1 at
> 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?

...some calculations...
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?