Skip to content

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

class method

FileUtils.cd

cd(dir, verbose: nil) { |dir| ... }

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 also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1