1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Ruby] File operations memo

Last updated at Posted at 2016-09-21

Some memo when doing some file operations with ruby.

# Get files recursively
Dir.glob("**/*.txt") do |f|
  # Do something..
end

# Directory check
Dir.exist?(directory_name)

# File check
File.exist?(file_name)

# Get file name from path
File.basename(path)

# Get directory name from path
File.dirname(path)

# Create directory recursively
FileUtils.mkdir_p(dir_path)

# Copy
FileUtils.cp(source_file, destination_dir)

# Any command
`mv #{source} #{destination}`
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?