Their input should be a directory in c:\folder\subfolder\ format. Additionally I don’t want it to try to run unless the directory contains .flv files. So it needs to exist AND contain .flv files. Otherwise it should ask the user to input another directory.
The code also cleans up the slashes, and adds a trailing slash, which I need for other parts of the program. What I have works when given a directory that exists and contains the .flv files, but if it doesn’t contain .flv files it just ends the program instead of asking for additional input; meaning it porceeds as long as the directory exists, even if it doesn’t have any .flv files.
def is_valid_dir()
input = "nil"
until File.directory?(input) && Dir.glob("#{input}*.flv")
puts "Enter the full directory path of the flv files."
input = gets.chomp
if input[-1..-1] == '/'
# Do nothing if it already
# ends with a forward slash.
else
input += '/'
end
end
input.gsub!('\\', '/')
return input
end
Dir.globreturns an empty array if there are no matches; check its length.Also, you say the input should be backslashy, but are checking for a forward slash. That aside, idiomatically you’re probably write that as: