To delete a file in Ruby, you need to use the File.delete or File.unlink method. To delete a CSV file, simply call one of these methods with the path of the file:
main.rb90 chars6 lines
If you want to ensure that the file exists before attempting to delete it, you can use the File.exist? method:
main.rb73 chars4 lines
Alternatively, you can use the FileUtils module, which provides a shorthand method FileUtils.rm for deleting files:
main.rb54 chars4 lines
Note that this method also allows you to delete multiple files at once, and has additional options for recursive deletion and error handling.
gistlibby LogSnag