简体   繁体   English

删除Ruby中所有文件的方法

[英]Method to delete all files in Ruby

I will probably kick myself after this but I have created a method within my cucumber application that will delete all files in a directory but it doesn't seem to execute as the files still exist after running it, though if i jump into my console and run the commands step by step it works. 我可能会在这之后踢自己但是我已经在我的黄瓜应用程序中创建了一个方法,它将删除目录中的所有文件,但它似乎没有执行,因为文件在运行后仍然存在,但是如果我跳进我的控制台并且逐步运行命令它的工作原理。

Any reason why this would not work when calling the method itself? 有什么理由在调用方法本身时这不起作用?

def clean_reports
  js_error_path = File.join(File.dirname(__FILE__), '/report/js_errors')
  screenshot_path = File.join(File.dirname(__FILE__), '/report/screenshots')
  FileUtils.rm_rf(Dir.glob(js_error_path + '/*'))
  FileUtils.rm_rf(Dir.glob(screenshot_path + '/*'))
end

What would be handy is if I could just call FileUtils.rm_rf just once? 如果我只能调用FileUtils.rm_rf一次,那会有什么用处? is this possible? 这可能吗?

My directory structure is like so 我的目录结构是这样的

-cucumber_tests
  -report
   -js_errors
     (files)
   -screenshots
     (files)

Thanks 谢谢

以下行将有所帮助,

FileUtils.rm_rf(Dir['./report/js_errors', './report/screenshots']) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM