I’m a Ruby newb, so this is probably not coded in the most efficient
manner.
I’m trying to read through a list of folder and convert my wav files to
flac. The below code works with most files but some blow up and break at
spaces and I can’t figure out where my error is. This worked for most of
the files in my folder.
Dir.glob(".wav") do |filename|
mybasename = File.basename("#{filename}",’.’)
mybasename += “.flac”
puts “Calling avconv -i ‘#{filename}’ ‘#{mybasename}’”
%x[avconv -i ‘#{filename}’’#{mybasename}’]
end
Did you type that out manually or copy it directly? You’re missing the
space between “’#{filename}’’#{mybasename}’”
There should be a space between the middle “’” characters.
You’re also using single quotes / apostrophes around a string containing
the same character. If you take “When it’s” and surround it with two “’”
characters, that’s 3 single quotes, making it terminate incorrectly.
I’m not sure how I didn’t stumble on this before, but the shellescape
option looks like it should be used for all output you are trying to
pass to bash.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.