What is the best way to get an empty temporary directory in Ruby on Rails?

后端 未结 9 608

What is the best way to get a temporary directory with nothing in it using Ruby on Rails? I need the API to be cross-platform compatible. The stdlib tmpdir won\'t work.

9条回答
  •  时光取名叫无心
    2020-12-28 13:12

    require 'tmpdir' # not needed if you are loading Rails
    tmp_dir = File.join(Dir::tmpdir, "my_app_#{Time.now.to_i}_#{rand(100)}")
    Dir.mkdir(tmp_dir)
    

    Works for me.

提交回复
热议问题