如何檢查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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章