Ruby文件处理相关代码


To find the size of a file in Ruby, you can use the size method provided by the File class. The size method returns the size of the file in bytes. Here's an example:
size = File.size("path/to/your/file")
puts("File size is #{size} bytes.")

Alternatively, you can use the IO class to open the file and then use the size method. Here's an example:

file = File.open("path/to/your/file")
file_size = file.size
file.close

In the above example, File.open is used to open the file and create an instance of IO. The size method is then called on this instance to determine the size of the file. Finally, the file is closed and the size is printed to the console.


文件删除
File.delete("path/to/your/file")

文件创建、修改、最近查看时间:
File.ctime("path/to/your/file")  # create
File.mtime("path/to/your/file") # modify
File.atime("path/to/your/file")  #access
阅读量: 316
发布于:
修改于: