Skip to content

Instantly share code, notes, and snippets.

@adamjmurray
Created April 12, 2012 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamjmurray/2363725 to your computer and use it in GitHub Desktop.
Save adamjmurray/2363725 to your computer and use it in GitHub Desktop.
How to detect that the case for a file path is correct on a case-insensitive file system
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment