Only a few notes:
- Creating
dir_pathsas an empty array, then on the next line immediately appendingprojects_pathto it seems odd vs. just adding it immediately. dir_paths[1...(dir_paths.length)]is equivalent todir_paths[1..-1]
With these changes:
require "date"
require "fileutils"
projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [project_paths]
["alpha", "beta", "gamma"].each do |name|
dir_paths << "#{projects_path}/team_#{name}"
end
if Dir.exist? projects_path
puts "#{projects_path} does already exist.\nExiting."
exit true
else
FileUtils.mkdir_p dir_paths
dir_paths[1..-1].each do |path|
FileUtils.touch [
"#{path}/logs.txt",
"#{path}/notes.txt" ]
end
puts "Created directory '#{projects_path}' successfully."
end
Given that if projects_path already exists, the program exits immediately, you could off course elide the else entirely.
require "date"
require "fileutils"
projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [project_paths]
["alpha", "beta", "gamma"].each do |name|
dir_paths << "#{projects_path}/team_#{name}"
end
if Dir.exist? projects_path
puts "#{projects_path} does already exist.\nExiting."
exit true
end
FileUtils.mkdir_p dir_paths
dir_paths[1..-1].each do |path|
FileUtils.touch [
"#{path}/logs.txt",
"#{path}/notes.txt" ]
end
puts "Created directory '#{projects_path}' successfully."