How to change a file extension ?

Example:
Changing from %program.r to %program.bak

Pitfall:
It cannot be done with a simple find and replace. Find and replace will fail
in some case like the following:

/d/rebol/prog.r/program.r -> /d/rebol/prog.bak/program.r
/d/rebol/prog.r/program.r -> /d/rebol/prog.bak/program.bak

Divide and conquer:
1. How to find the file extension ?
2. How to replace on extension with another ?

Solution 1:
short anwser : with find/last

The file extension is found like this.

myfile: %/d/rebol/prog.r/program.r
print find/last myfile "." ; .r

Solution 2:

infile: to-string %/d/rebol/prog.r/program.r
ext: find/last infile "."
outfile: copy/part infile (length? infile) - (length? ext)
append outfile ".bak"
print outfile

It seems to me a bit complicated. Does anyone have a better (simpler)
solution ?


 
______________________________________________________________________________
ifrance.com, l'email gratuit le plus complet de l'Internet !
vos emails depuis un navigateur, en POP3, sur Minitel, sur le WAP...
http://www.ifrance.com/_reloc/email.emailif


-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to