Check if a filename is a folder or a file

I have a little piece of Ruby code:

files.each do |file|
  FileUtils.mkdir_p(File.dirname(target))    
  FileUtils.cp_r(file, target, :verbose => true)
end

I would like to add a check like

if file is a folder
  # do this
if file is a file
  # do that

How do I implement in Ruby?


You can use File.directory?("name") and/or File.file?("name").


Also a good idea to check out Pathname#directory? and Pathname#file?