Skip to content

Instantly share code, notes, and snippets.

@adamjmurray
Created April 12, 2012 00:25
Show Gist options
  • Select an option

  • Save adamjmurray/2363725 to your computer and use it in GitHub Desktop.

Select an option

Save adamjmurray/2363725 to your computer and use it in GitHub Desktop.

Revisions

  1. adamjmurray created this gist Apr 12, 2012.
    10 changes: 10 additions & 0 deletions file_definitely_exists.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    class File
    # Does a case-sensitive check for file existence.
    # Unlike the normal File.exists? method on OS X with its case-insensitive-by-default FS
    def self.definitely_exists? path
    folder = File.dirname path
    filename = File.basename path
    # Unlike Ruby IO, ls, and find -f, this technique will fail to locate the file if the case is wrong:
    not %x( find "#{folder}" -name "#{filename}" ).empty?
    end
    end