DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone >

Tar2zip.rb

Snippets Manager user avatar by
Snippets Manager
·
Oct. 04, 05 · · Code Snippet
Like (0)
Save
Tweet
532 Views

Join the DZone community and get the full member experience.

Join For Free
Converts the given tarfile to a zipfile. You must have tar and zip in the system PATH. You will need to uncompress the tarfile or modify the script if you tar is compressed. 


#! /usr/bin/ruby
class Tar2Zip
	def run(dir, cmd)
		pwd = Dir.getwd
		print "cd ",dir, "\n"	
		Dir.chdir(dir)
		print cmd, "\n"
		system(cmd)
		print "cd ",pwd, "\n"	
		Dir.chdir(pwd)
	end
	def main(argv)
		tarfile=File.expand_path(argv[0])
		zipfile= File.join(File.dirname(tarfile), File.basename(tarfile,".tar"))+".zip"
		if File.exists?(zipfile)
			print zipfile, " already exists\n"
			return
		end	
		pwd = Dir.getwd
		basename = File.basename(tarfile)
		tmpdir = File.join("/tmp", basename)
		Dir.mkdir(tmpdir)
		run(tmpdir, "tar -xvf #{tarfile}")
		run(tmpdir, "zip -rm #{zipfile} .")
		Dir.unlink(tmpdir)
	end
end
Tar2Zip.new.main(ARGV)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • An Overview of 3 Java Embedded Databases
  • The Most Popular Kubernetes Alternatives and Competitors
  • Is Java Still Relevant?
  • 6 Things Startups Can Do to Avoid Tech Debt

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo