# frozen_string_literal: truerequire"dry/files"path="path/to/file"files=Dry::Files.new# read the file all at once, returning a stringfiles.read(path)# touch a file# create the intermediate directories if they not existfiles.touch(path)# write a file# create the intermediate directories if they not exist# if the file exists, replace the contentsfiles.write(path,"hello")# join the given pathsfiles.join("path","to","file")files.join("path",["to","file"])files.join("path/to/file")# expand the given path# the base directory is the current one# you can specify a base directoryfiles.expand_path(path)# base dir is Dir.pwd (implict)files.expand_path(path,"path/to/base/directory")# returns the path to the current directoryfiles.pwd# temporary changes the current directoryfiles.chdir("path/to/dir")dofiles.pwd# => "path/to/dir"end# creates intermediate directories for the given path (directory)files.mkdir("path/to/new/dir")# creates intermediate directories for the given path (file)files.mkdir_p("path/to/new/dir/file.rb")# creates "path/to/new/dir"# copy source file to destination# intermediate destination directories are created if they not existfiles.cp(path,"path/to/destination")# delete a filefiles.delete(path)# delete a directoryfiles.delete_directory("path/to/dir")# check if path exist (files and directories)files.exist?(path)# check if path is a directoryfiles.directory?(path)# check if path is an executable (files and directories)files.executable?(path)