Holla Tech - Learn

Deleting Files
 

We can delete a file using the File.delete method.
For example: 

File.delete(“test.txt”

 

NOTE!
Be careful, as this command deletes the file permanently.

Working with Files
 

When working with files, it is important to first check if the file exists in order to prevent an error.
The file? method provides an easy way of checking if the file exists.
For example:

File.open(“test.txt”) if File.file?(“text.txt”

 

The code above tests whether a file exists before opening it.

NOTE!
File.file? returns true if the file exists, and false if it does not.

BACK NEXT

CLICK ON THE BUTTON BELOW TO GO TO THE RUBY MAIN COURSE PAGE. 

RUBY MAIN COURSE PAGE

 


© License: All Rights Reserved 


CONTACT HOLLA TECH – LEARN SUPPORT