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
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: