O'Reilly logo

Wicked Cool Ruby Scripts by Steve Pugh

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

File Splitting

File Splitting

fileSplit.rb

A cool use of Ruby scripting is to split a large file into several smaller, symmetric files. I wrote this script for a friend who was having trouble sending files into and out of his corporate network since the network administrators wouldn't allow files over a certain size to be transferred—presumably for bandwidth reasons. This script worked like a charm.

The Code

 if ARGV.size != 2
     puts "Usage: ruby fileSplit.rb <filename.ext> <size_of_pieces_in_bytes>"
     puts "Example: ruby fileSplit.rb myfile.txt 10"
     exit
 end

 filename = ARGV[0]
 size_of_split = ARGV[1]

 if File.exists?(filename) file = File.open(filename, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required