[REBOL] How to change a file extension ?
From: pat665::ifrance::com at: 13-Jan-2002 17:52
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 ?