Skip to content

Instantly share code, notes, and snippets.

Created July 24, 2015 16:10
Show Gist options
  • Save anonymous/fa9cb9e53a8130d325b6 to your computer and use it in GitHub Desktop.
Save anonymous/fa9cb9e53a8130d325b6 to your computer and use it in GitHub Desktop.
directory_name = %w[Original Modified]
directory_name.each do |dir|
if dir.exists?(directory_name)
abort("These folders already exist. No further action will be taken.")
else
Dir.mkdir(directory_name[0]) unless File.exists?(directory_name[0])
Dir.mkdir(directory_name[1]) unless File.exists?(directory_name[1])
end
end
@grosscol
Copy link

I assume you have a list of directory pairs. Each element of the directory_name array is an array of size 2 where the first element is original and the second is modified. Looks like these are path strings.

# For each pair of directories, check if they exist.  If not, create them.
# The mkdir call will fail if the parent directories do not exist.
directory_name.each do |dpair|
  Dir.mkdir(dpair[0]) unless File.exists?(dpair[0])
  Dir.mkdir(dpair[1]) unless File.exists?(dpair[1])
end

@grosscol
Copy link

I assume you have a list of directory pairs. Each element of the directory_name array is an array of size 2 where the first element is original and the second is modified. Looks like these are path strings.

# For each pair of directories, check if they exist.  If not, create them.
# The mkdir call will fail if the parent directories do not exist.
directory_name.each do |dpair|
  Dir.mkdir(dpair[0]) unless File.exists?(dpair[0])
  Dir.mkdir(dpair[1]) unless File.exists?(dpair[1])
end

@grosscol
Copy link

directory_name.each do |dname|
  Dir.mkdir(dname) unless File.exists?(dname)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment