Work with files / Basic operations

dir_path = Dir.pwd
file_path = File.join(dir_path, "file.txt")
# prepare the file
File.write(file_path, "Hello, world!")

# file size
file_size = File.size(file_path)

# file modification date
date_modified = File.mtime(file_path)

# file creation date
creation_date = File.ctime(file_path)

# is readable file
is_readable = File.readable?(file_path)

# is writable file
is_writable = File.writable?(file_path)

# file extension
extension = File.extname(file_path)

# file name
file_name = File.basename(file_path)

# file name without extension
file_name_only = file_name[0
    file_name.length - extension.length]

# file directory
file_dir = File.dirname(file_path)

puts "file_size is #{file_size}"
puts "date_modified is #{date_modified}"
puts "creation_date is #{creation_date}"
puts "is_readable is #{is_readable}"
puts "is_writable is #{is_writable}"
puts "extension is '#{extension}'"
puts "file_name is '#{file_name}'"
puts "file_name_only is '#{file_name_only}'"
puts "file_dir is '#{file_dir}'"