Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

FileUtils.chdir

chdir(dir, verbose: nil)

Alias of .cd

Changes the current directory to the directory dir.

If this method is called with block, resumes to the previous working directory after the block execution has finished.

Example
FileUtils.cd('/')  # change directory

FileUtils.cd('/', verbose: true)   # change directory and report it

FileUtils.cd('/') do  # change directory
  # ...               # do something
end                   # return to original directory
See also .cd #chdir .chmod .chmod_R also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0