如何检查Ruby中是否存在给定目录 - How to check if a given directory exists in Ruby

问题:

I am trying to write a script which automatically checks out or updates a Subversion URL based on whether a specified directory exists or not.我正在尝试编写一个脚本,该脚本根据指定的目录是否存在自动检出或更新 Subversion URL。

For some reason, my code isn't working and always returns true even if it's false:出于某种原因,我的代码不起作用,即使它是假的,也总是返回

def directory_exists?(directory)
  return false if Dir[directory] == nil
  true
end

What am I doing wrong?我究竟做错了什么?


解决方案:

参考一: https://en.stackoom.com/question/4YJW
参考二: https://stackoom.com/question/4YJW
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章