# Batch scrambling

**URL:** <https://forums.sketchup.com/t/batch-scrambling/8442>\
**Category:** Ruby API\
**Created:** [March 13, 2015, 3:20pm UTC](https://forums.sketchup.com/t/batch-scrambling/8442 "2015-03-13T15:20:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![barry\_milliken\_droid](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/barry_milliken_droid/32/4612_2.png) [@barry\_milliken\_droid](https://forums.sketchup.com/u/barry_milliken_droid)\
**Post date:** [March 13, 2015, 3:20pm UTC](https://forums.sketchup.com/t/batch-scrambling/8442/1 "2015-03-13T15:20:07Z")

</div>

Apparently there is a way to scramble a whole subfolder of rb files.  
My new extension has 26 rb files. I’m doing them one at a time.  
But maybe for future updates it would be handy.  
How do you call an external exe and loop through a folder of files?

---

<div class="post-metadata">

**Author:** ![Aerilius](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@Aerilius](https://forums.sketchup.com/u/Aerilius)\
**Post date:** [March 13, 2015, 4:05pm UTC](https://forums.sketchup.com/t/batch-scrambling/8442/2 "2015-03-13T16:05:46Z")

</div>

Just pass in **multiple parameters** 👴

> [@SketchUpRubyScrambler](#):
>
> `SketchUp Ruby Scrambler version 1.0 Usage -- Scrambler file1.rb [file2.rb] ... Creates file1.rbs [file2.rbs] ...`

_Too bad_ that it doesn’t handle wildcards (at least in the \*#☠↯!\* Windows cmd)…  
`SketchUpRubyScrambler *.rb`  
…but you could instead drag and drop all files into the command prompt, create your own script, use a better command prompt (maybe PowerShell) or use a loop:

```auto
for %i in (dir subfolder/*.rb) do SketchUpRubyScramblerWindows.exe %i

```

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [March 13, 2015, 4:52pm UTC](https://forums.sketchup.com/t/batch-scrambling/8442/3 "2015-03-13T16:52:54Z")

</div>

Here is an extract of the Ruby script I use to build one of my extension:

```auto
  puts "Scrambling RB files..."

  rb_files_pattern = File.join(build_path, extension_name, " **/** /*.rb")
  rb_files = Dir.glob(rb_files_pattern)

  scrambler_exec = File.join( __dir__ , "scrambler")
  scambler_command = "#{scrambler_exec} #{rb_files.join(" ")}"
  p system(scambler_command)

  FileUtils.remove(rb_files)

```

After that it also builds the RBZ package:

```auto
### Package ####################################################################

puts "Creating ZIP archive..."
puts "Source: #{build_path}"
puts "Destination: #{archive}"

if File.exist?(archive)
  puts "Archive already exist. Deleting existing archive."
  File.delete(archive)
end

Zip::File.open(archive, Zip::File::CREATE) do |zipfile|
  build_files = Dir.glob(build_files_pattern)
  build_files.each { |file_item|
    next if File.directory?(file_item)
    pathname = Pathname.new(file_item)
    relative_name = pathname.relative_path_from(build_pathname)
    puts "Archiving: #{relative_name}"
    zipfile.add(relative_name, file_item)
  }
end

puts "Packing done!"
puts "#{archive}"

```

I’ve been meaning to extract the gist of it into an example and put it on GitHub.

Attaching the whole script:  
[PackageExtension.rb](https://forums.sketchup.com/uploads/default/4798/1c7d7c5fc64cd66b.rb) (3.7 KB)

The nice thing about making the build tools in ruby instead of system shell scripts is that you can run them on both platform. On OSX they run out of the box, on Windows you just use the Windows Ruby installer.

---

<div class="post-metadata">

**Author:** ![barry\_milliken\_droid](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/barry_milliken_droid/32/4612_2.png) [@barry\_milliken\_droid](https://forums.sketchup.com/u/barry_milliken_droid)\
**Post date:** [March 13, 2015, 8:24pm UTC](https://forums.sketchup.com/t/batch-scrambling/8442/4 "2015-03-13T20:24:50Z")

</div>

Terrific! Thank you.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [March 14, 2015, 7:39pm UTC](https://forums.sketchup.com/t/batch-scrambling/8442/5 "2015-03-14T19:39:28Z")

</div>

> [@Aerilius](#):
>
> …but you could instead drag and drop all files into the command prompt, …

I just drop a copy the scrambler.exe file into the folder, then grab all the rb files via selection and hold+drag and drop them all onto the executable. The shell does the loop for us.

---

<div class="post-metadata">

**Author:** ![barry\_milliken\_droid](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/barry_milliken_droid/32/4612_2.png) [@barry\_milliken\_droid](https://forums.sketchup.com/u/barry_milliken_droid)\
**Post date:** [March 15, 2015, 4:17pm UTC](https://forums.sketchup.com/t/batch-scrambling/8442/6 "2015-03-15T16:17:26Z")

</div>

Gosh. I didn’t realize that Bill Gates was so smart!  
We have to avoid the old pitfall:  
“When you own a hammer (like ruby script) everything looks like a nail.”
