How do I move a file with Ruby?

前端 未结 6 1228
醉酒成梦
醉酒成梦 2020-12-07 19:54

I want to move a file with Ruby. How do I do that?

6条回答
  •  时光说笑
    2020-12-07 20:02

    You can use FileUtils to do this.

    #!/usr/bin/env ruby
    
    require 'fileutils'
    
    FileUtils.mv('/tmp/your_file', '/opt/new/location/your_file')
    

    Remember; if you are moving across partitions, "mv" will copy the file to new destination and unlink the source path.

提交回复
热议问题