Log in

No account? Create an account
Adventures in Ruby: Better File Extensions! 
3rd-Oct-2014 03:43 pm
bannakaffalatta, short
After a bit of research, I found a much better way to do the file name manipulation I was talking about in my previous post.

Basically, it boils down to:

require "pathname"
input_file = Pathname.new(ARGV[0])
new_base = (input_file.basename(input_file.extname)).to_s + "_counts" + input_file.extname.to_s
output_file = input_file.dirname + Pathname.new(new_base)

I used Pathname instead of File because the documentation suggests that it's more robust at dealing with different file pathing conventions on different OSes.

I'm a little dubious about the dance I had to do there of converting path fragments to strings, concatenating them, and then converting back to a pathname, but trying to concatenate the path fragments directly kept giving me extra / in the path.
3rd-Oct-2014 11:16 pm (UTC)
Sorry to be practically off-topic, but does your Subject line play on the phrase "The Adventures of Ruby," perchance?
4th-Oct-2014 09:48 pm (UTC)
No, it doesn't. Although having googled it, I'm intrigued. Thanks for pointing out my (unintentional) reference!
5th-Oct-2014 03:50 am (UTC)
I have such a long history with that series (and the company that made it) that I sometimes feel I was a part of its creation.

(Not at all true, although I was a part of its dissemination back when I had a radio show)

Explore and enjoy.

This page was loaded Jul 19th 2019, 5:58 am GMT.