Whats the best way to delete multiple files with a given prefix in the
'tmp' folder of a RAILS application?
File.delete works great if I have just one file and I know what the file
name is. But I'm creating PDF documents as
'user_name_some_report_name_yyyymmddhhmmss.pdf'
I'd like to use something like
'File.delete("#{RAILS_ROOT}/tmp/pdfs/user_name_some_report_name*")'.
Why are you using instance variables here? The file mask and list of
files seem to be of use only to the method in context, so just use
local variables...
The File.join here is useless; File.join concatenates each argument
passed to it with the directory separator; it does nothing to the
individual arguments. You probably wanted to pass each part of the
pathname as separate arguments, without any directory separator.
You do not need to iterate through each of user_files; File.delete
deletes each filename passed to it. Just use File.delete *user_files