Dir.chdir "directory" # Usage with a block Dir.chdir "directory" do # block run inside "directory" puts Dir.pwd end # cwd is unaffected afterwards puts Dir.pwd