I have cleaned up the Ruby code in that 2016 link, How do I copy folder/directory structure without copying the contents .
After signing into the support communities, copy and paste the following code into Script Editor, compile, and run it. This is a scrollable window so click at the top of it and drag downward to select all of the text. Due to the hosting software, this scrollable window will appear differently when signed out, than when signed in.
Tested successfully on macOS High Sierra 10.13.4 with Ruby 2.3.3p222.
set dest_string to "Choose a destination folder. If it does not exist," & return & ¬
"make a new folder (give it a name), and choose the blank folder"
try
set srcfolder to POSIX path of (choose folder with prompt "Choose a source folder:")
set destfolder to POSIX path of (choose folder with prompt dest_string)
on error errmsg number errnbr
if errnbr = -128 then
display dialog "User cancelled."
end if
return
end try
set argvector to srcfolder's quoted form & space & destfolder's quoted form
if (dupe_folder(argvector) as boolean) is equal to true then
display dialog "New folders structure complete:" & return & destfolder as text
else
display dialog "Ruby structure duplication process has failed."
end if
return
on dupe_folder(args)
return do shell script "ruby <<'EOF' - " & args & "
#!/usr/bin/ruby
# frozen_string_literal: true
# attribution: Craig Williams at MacScripter: http://macscripter.net/viewtopic.php?id=31401
require 'find'
require 'fileutils'
source, dest = ARGV.map { |d| File.expand_path(d) }
IGNORE = ['.pages', '.numbers', '.key', '.rtfd', '.app', '.scptd', '.bundle',
'.workflow', '.framework', '.dylib', '.photolibrary', '.photoslibrary',
'.gem'].freeze
Find.find(source) do |item|
next if !File.directory?(item) || item == source
Find.prune if IGNORE.include?(File.extname(item))
FileUtils.mkdir_p(dest + item.gsub(source, ''))
end
# returns true if dest dir is not empty, indicating success
puts !Dir.glob(File.join(dest, '**')).empty?
EOF"
end dupe_folder