Arexx (44/67)

From:Robert Wilson
Date:20 Oct 99 at 22:01:13
Subject:Re: Filenumbering

From: Robert Wilson <robert@dynamix.force9.co.uk>

Hi Michael,

> The Problem: I export a file from a graphic-program with everytime an
> other filecontent but with everytime the same filename... Target is to
> automatically renumber all the files because they should not be
> overwritten.

> So I need a routine which checks if file(.x) exists and if so give the
> new one a higher number. Ideal is when the first file has no extension
> but it's not a must :)

> file
> file.1
> file.2
> and so on

Take a look at the function below;

/* */

lastframe:

highest = 0
address 'COMMAND'
'c:list' destpath''basename'_???'extension 'nohead quick LFORMAT %N
>t:afmlist.tmp'
if ~open(file,'t:afmlist.tmp',r) then call die('Unable to open temporary
file list')
do until eof(file)
temp = readln(file)
if length(temp) ~= 0 then do
numero = substr(temp,pos('_',temp)+1,pos('.',temp)-pos('_',temp)-1)
if numero > highest then highest = numero
end
end
call close(file)

'run <>nil: c:delete t:afmlist.tmp FORCE QUIET'

return

/* */

I wrote this for a script of mine some months ago. Seems to work very well.
Call function and then save file using something like...

filename = destpath''basename'_'right(loop+highest,3,'0')''extension

Obviously you need to define variables before hand ;-)

Files are named "pic_001.iff" etc... To increase naming system beyond
beyond 999 (lets say 99999), just create filename to save using something
like...

filename = destpath''basename'_'right(loop+highest,5,'0')''extension

Hope this helps?

Rob



robert@dynamix.f9.co.uk
http://www.dynamix.f9.co.uk

--------------------------- ONElist Sponsor ----------------------------

??? Computer Questions ==> Free Answers From Live Experts ! ! !
go to EXPERTCITY.COM
<a href=" http://clickme.onelist.com/ad/expertcity15 ">Click Here</a>

------------------------------------------------------------------------
ARexx mailing list - No flames, no overquoting, no crossposting. Unsubscribe: Blank mail to mailto:arexx-unsubscribe@onelist.com