DEV Community

Yuta Goto
Yuta Goto

Posted on

Rubyでディレクトリ操作をする

これは .ごっ!のアドベントカレンダー の14日目の記事です。

rubyのバージョン3.2での情報です。

カレントディレクトリのパスを変更

Dir.chdir("/var/log") 
Enter fullscreen mode Exit fullscreen mode

現在のディレクトリを取得

Dir.chdir("/tmp") Dir.getwd # => "/tmp"  
Enter fullscreen mode Exit fullscreen mode

カレントディレクトリ配下にあるファイルエントリ取得

Dir.children(".") => [".circleci", ".codespellrc", ".gem_rbs_collection", ".git", ".github", ".gitignore", ".rspec", ".rspec_status", ".rubocop.yml", ".vscode", "Gemfile", "Gemfile.lock", "LICENSE.txt", "README.md", "Rakefile", "Steepfile", "bin", "config", "sample.gemspec", "lib", "pkg", "rbs_collection.lock.yaml", "rbs_collection.yaml", "sig", "spec"] 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)