makersacademy / learn_to_program

For submitting exercises from the Chris Pine Learn to Program Book
11 stars 400 forks source link

Ch11. Trying to make a method to check whether or not a batch has already been used #383

Closed JackOddy closed 8 years ago

JackOddy commented 8 years ago

I've written a method that, to my understanding, checks whether or not the current working directory has any files starting with the current batch name followed by any number of digits and then a .JPG/.jpg.

I think its the regex /\d+/, i want that to mean any numbers.

I've looked on a lot of different websites but I must be missing something to make it work..

Method runs and doesn't through up any errors but also doesnt actually work as the program goes on to overwrite files already in the directory. Code dump below:

def batch_name bname

  if File.exist?("#{bname}#{/\d+/}.{JPG,jpg}")
    puts "Error. A batch already exists with this name.\n
    Please choose another name for this batch."
    batch_name gets.chomp
  else
    bname
  end

end