I was wondering though if instead of the temp variable I could just do:
fileroot, type = filename.split(/regex here?/)
I cannot find a way to write a regex that only matches the last period in the
filename. Is there an elegant way to do this?
Thanks,
-d
···
--
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972
I was wondering though if instead of the temp variable I could just do:
fileroot, type = filename.split(/regex here?/)
I cannot find a way to write a regex that only matches the last period in the
filename. Is there an elegant way to do this?
Thanks,
-d
--
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972
On 6/6/06, darren kirby <bulliver@badcomputer.org> wrote:
> fileroot, type = filename.split(/regex here?/)
>
> I cannot find a way to write a regex that only matches the last period in
> the filename. Is there an elegant way to do this?
Thanks. I should have guessed there would be a builtin for it...
-d
--
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972
I think you mean f.basename(f.extname) for the basename without the extensions.
-austin
···
On 6/6/06, Matthew Smillie <M.B.Smillie@sms.ed.ac.uk> wrote:
On Jun 7, 2006, at 2:54, Austin Ziegler wrote:
> On 6/6/06, darren kirby <bulliver@badcomputer.org> wrote:
>> fileroot, type = filename.split(/regex here?/)
>
>> I cannot find a way to write a regex that only matches the last
>> period in the
>> filename. Is there an elegant way to do this?
>
> ext = File.extname(filename)
> file = File.basename(filename, ext)
Equivalent, but I like the semantics a little better
require 'pathname'
f = Pathname.new(filename)
f.basename
f.extname
pathname is very handy - see the standard library docs: http://ruby-
doc.org/stdlib/libdoc/pathname/rdoc/index.html