Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

ruby
time
communitycreator
changetime

What is File.ctime in Ruby?

okwudili onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The ctime() method of a File instance in Ruby is used to return the change time for a particular file. Note that this time is when the file’s directory was changed, not the file itself.

Syntax

File.ctime(file_name)

Parameters

file_name is the name of the file.

Return value

The value returned is the directory change time for the file.

Code example

main.rb
test.rb
test.txt
# get file
fn1 = "test.txt"
fn2 = "test.rb"
# get change time
puts File.ctime(fn1)
puts File.ctime(fn2)
Get change times of files in Ruby

Explanation

  • Files test.rb and test.txt were created. We also have the main.rb file containing our application code.
  • Line 2 and 3: we got the file names.
  • Line 6 and 7: the change times of the files were obtained, and the values were printed to the console.

RELATED TAGS

ruby
time
communitycreator
changetime

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring