Created
April 12, 2012 00:25
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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