the*_*Man 133
标准文件模块具有通常的文件测试可用:
RUBY_VERSION # => "1.9.2"
bashrc = ENV['HOME'] + '/.bashrc'
File.exist?(bashrc) # => true
File.file?(bashrc) # => true
File.directory?(bashrc) # => false
Run Code Online (Sandbox Code Playgroud)
你应该能够找到你想要的东西.
OP:"谢谢,但我需要三个真或假"
显然不是.好的,试试类似:
def file_dir_or_symlink_exists?(path_to_file)
File.exist?(path_to_file) || File.symlink?(path_to_file)
end
file_dir_or_symlink_exists?(bashrc) # => true
file_dir_or_symlink_exists?('/Users') # => true
file_dir_or_symlink_exists?('/usr/bin/ruby') # => true
file_dir_or_symlink_exists?('some/bogus/path/to/a/black/hole') # => false
Run Code Online (Sandbox Code Playgroud)
Gin*_*kas 13
为什么不定义自己的功能File.exists?(path) or File.symlink?(path)并使用它?
| 归档时间: |
|
| 查看次数: |
56348 次 |
| 最近记录: |