Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7647011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:21:26+00:00 2026-05-31T10:21:26+00:00

Using Ruby (1.9.3) I need to replace a single file in a zip archive.

  • 0

Using Ruby (1.9.3) I need to replace a single file in a zip archive.

The situation is as follows. I have ~1000 zip archives that need to be updated, specifically one file in each of them needs to be replaced. The archives are all of the same structure. Is there a quick and dirty way for Ruby, or a library/gem for Ruby, to simply say “replace the file in this zip archive with this file on the filesystem”?

I’ll work on a solution of my own in the meantime.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:21:27+00:00Added an answer on May 31, 2026 at 10:21 am

    You can use the zip command, called from the ruby, which probably will be the best solution. From the zip manpage zip manpage

           -d
       --delete
              Remove (delete) entries from a zip archive.  For example:
    
                     zip -d foo foo/tom/junk foo/harry/\* \*.o
    
              will remove the entry foo/tom/junk, all of the files that start with foo/harry/, and all of the files that end with .o (in any path).  Note that  shell  path‐
              name expansion has been inhibited with backslashes, so that zip can see the asterisks, enabling zip to match on the contents of the zip archive instead of the
              contents of the current directory.  (The backslashes are not used on MSDOS-based platforms.)  Can also use quotes to escape the asterisks as in
    
                     zip -d foo foo/tom/junk "foo/harry/*" "*.o"
    
              Not escaping the asterisks on a system where the shell expands wildcards could result in the asterisks being converted to a  list  of  files  in  the  current
              directory and that list used to delete entries from the archive.
    
              Under  MSDOS,  -d  is  case sensitive when it matches names in the zip archive.  This requires that file names be entered in upper case if they were zipped by
              PKZIP on an MSDOS system.  (We considered making this case insensitive on systems where paths were case insensitive, but it is possible the archive came  from
              a  system  where case does matter and the archive could include both Bar and bar as separate files in the archive.)  But see the new option -ic to ignore case
              in the archive.
    

    If you want a pure ruby solution take a look at ZipFileSystem

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have unfortunately wandered into a situation where I need regex using Ruby. Basically
I'm using ruby 1.9.3 and I need to compare two hashes that have different
I've been using Textmate for Ruby/Python scripting for awhile and now have a need
Using Ruby 1.9.2 I need to parse a CSV file, and output lines with
I'm using ruby to read a file and I need to somehow parse some
I need to make an if statement using Ruby that checks to see if
I need to archive multiple files using ruby, but I need to archive them
I need to print escaped characters to a binary file using Ruby. The main
I'm using ruby-opencv to do some image processing. I have an IplImage object that
I'm using Ruby 1.8.7. I have the following array of hashes. I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.