Syntax Error in script for duplicating folder structure

Frustratingly I cannot reply to a comment in another discussion, they get closed nowadays. So have to make a new one here and hope that the poster sees it..?


In this comment: Re: How do I copy folder/directory structure without copying the contents?


@VikingOSX (be nice if I could tag people too) ... gave their script for copying and recreating a folder hierarchy without the contents in MacOS Finder.


I tried that script but got an error as follows:


Syntax Error

Expected expression but found end of line.


(tried to upload a screenshot to insert here, selected the image, then clicked 'Insert Image' button, nothing happened.


Any suggestions as to what the error may be in the script? Thanks

MacBook Pro (15-inch Mid 2012), macOS Sierra (10.12.4), SSD, Optical Drive swapped for HD

Posted on May 6, 2018 7:38 PM

Reply
Question marked as Top-ranking reply

Posted on May 7, 2018 8:00 AM

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

Similar questions

4 replies
Question marked as Top-ranking reply

May 7, 2018 8:00 AM in response to VikingOSX

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

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Syntax Error in script for duplicating folder structure

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.