Zip an existing directory?

Discussion in 'Ruby' started by Peter Marks, Oct 29, 2007.

  1. Peter Marks

    Peter Marks Guest

    Hello,

    I am trying to zip an existing directory using the following code:

    system("zip /Users/petermarks/Desktop/orbus/public/1/daily/2007-10-29")

    but get this error:

    zip error: Nothing to do!
    (/Users/petermarks/Desktop/orbus/public/1/daily/2007-10-29.zip)

    I've seen some tutorials for archiving using the rubyzip gem, but they
    all involve manually moving files into an archive instead of archiving
    an existing directory. I'm assuming rubyzip is overkill for this?

    Thanks,

    Peter
    --
    Posted via http://www.ruby-forum.com/.
    Peter Marks, Oct 29, 2007
    #1
    1. Advertising

  2. Peter Marks

    Phlip Guest

    > I am trying to zip an existing directory using the following code:
    >
    > system("zip /Users/petermarks/Desktop/orbus/public/1/daily/2007-10-29")
    >
    > but get this error:
    >
    > zip error: Nothing to do!
    > (/Users/petermarks/Desktop/orbus/public/1/daily/2007-10-29.zip)


    How does zip work on the command line? What does zip --help tell you?

    You must list some files for it to zip, or at least a wildcard *.

    --
    Phlip
    Phlip, Oct 30, 2007
    #2
    1. Advertising

  3. Phlip wrote:
    >> I am trying to zip an existing directory using the following code:
    >>
    >> system("zip /Users/petermarks/Desktop/orbus/public/1/daily/2007-10-29")
    >>
    >> but get this error:
    >>
    >> zip error: Nothing to do!
    >> (/Users/petermarks/Desktop/orbus/public/1/daily/2007-10-29.zip)

    >
    > How does zip work on the command line? What does zip --help tell you?
    >
    > You must list some files for it to zip, or at least a wildcard *.
    >


    At least on Linux / Cygwin, the command to make a zip archive from a
    directory is

    $ zip archive-file.zip /path/to/archive

    The first parameter is the output archive file name and the *second*
    parameter is the path you want to archive. So what it's complaining
    about is that you didn't give it the output archive file name, just the
    path that you wanted to archive.
    M. Edward (Ed) Borasky, Oct 30, 2007
    #3
  4. Peter Marks

    Guest

    Thanks for the help guys. I am developing in osx and will deploy in
    ubuntu (this is for a rails app). My original command does not work in
    the command line, nor does zip --help on my local machine.

    The command you suggested, Ed, gives the following response:

    adding: Users/petermarks/Desktop/orbus/public/1/daily/2007-10-29/
    (stored 0%)

    The archive it produces contains the folders of the intended archive's
    path, but not the contents of the "2007-10-29" folder. I need to archive
    the contents of that folder. Any other ideas?

    Thanks again,

    Peter
    --
    Posted via http://www.ruby-forum.com/.
    , Oct 30, 2007
    #4
  5. Peter Marks wrote:
    > Thanks for the help guys. I am developing in osx and will deploy in
    > ubuntu (this is for a rails app). My original command does not work in
    > the command line, nor does zip --help on my local machine.
    >
    > The command you suggested, Ed, gives the following response:
    >
    > adding: Users/petermarks/Desktop/orbus/public/1/daily/2007-10-29/
    > (stored 0%)
    >
    > The archive it produces contains the folders of the intended archive's
    > path, but not the contents of the "2007-10-29" folder. I need to archive
    > the contents of that folder. Any other ideas?
    >
    > Thanks again,
    >
    > Peter


    zip -r archive.zip
    Users/petermarks/Desktop/orbus/public/1/daily/2007-10-29/

    I forgot the "-r" (for recursive).
    M. Edward (Ed) Borasky, Oct 30, 2007
    #5
  6. Peter Marks

    Peter Marks Guest

    > zip -r archive.zip
    > Users/petermarks/Desktop/orbus/public/1/daily/2007-10-29/
    >
    > I forgot the "-r" (for recursive).


    Thanks Ed, that archives the contents of "2007-10-29". Do you know if
    there is a way to make the new archive only contain the contents of
    "2007-10-29" and not the folders of the path leading to it?
    --
    Posted via http://www.ruby-forum.com/.
    Peter Marks, Oct 30, 2007
    #6
  7. Peter Marks wrote:
    >> zip -r archive.zip
    >> Users/petermarks/Desktop/orbus/public/1/daily/2007-10-29/
    >>
    >> I forgot the "-r" (for recursive).

    >
    > Thanks Ed, that archives the contents of "2007-10-29". Do you know if
    > there is a way to make the new archive only contain the contents of
    > "2007-10-29" and not the folders of the path leading to it?


    $ cd /Users/petermarks/Desktop/orbus/public/1/daily/
    $ zip -r archive.zip 2007-10-29

    There's another way, but I don't remember what it is.
    M. Edward (Ed) Borasky, Oct 30, 2007
    #7
  8. Peter Marks

    Peter Marks Guest

    M. Edward (Ed) Borasky wrote:
    > $ cd /Users/petermarks/Desktop/orbus/public/1/daily/
    > $ zip -r archive.zip 2007-10-29
    >
    > There's another way, but I don't remember what it is.


    I think I'll digg up that other way in order to write this into a ruby
    function. Thanks again for you guidance Ed. :)
    --
    Posted via http://www.ruby-forum.com/.
    Peter Marks, Oct 30, 2007
    #8
  9. Peter Marks wrote:
    > M. Edward (Ed) Borasky wrote:
    >> $ cd /Users/petermarks/Desktop/orbus/public/1/daily/
    >> $ zip -r archive.zip 2007-10-29
    >>
    >> There's another way, but I don't remember what it is.

    >
    > I think I'll digg up that other way in order to write this into a ruby
    > function. Thanks again for you guidance Ed. :)

    Isn't there a Ruby library that does this without calling the
    command-line function?
    M. Edward (Ed) Borasky, Oct 30, 2007
    #9
  10. Peter Marks

    Peter Marks Guest

    M. Edward (Ed) Borasky wrote:
    > Isn't there a Ruby library that does this without calling the
    > command-line function?


    Apparently there's rubyzip. I haven't really looked into that too much,
    but will if I can't get this to work right.
    --
    Posted via http://www.ruby-forum.com/.
    Peter Marks, Oct 30, 2007
    #10
  11. Peter Marks

    7stud -- Guest

    M. Edward (Ed) Borasky wrote:
    > Peter Marks wrote:
    >>> zip -r archive.zip
    >>> Users/petermarks/Desktop/orbus/public/1/daily/2007-10-29/
    >>>
    >>> I forgot the "-r" (for recursive).

    >>
    >> Thanks Ed, that archives the contents of "2007-10-29". Do you know if
    >> there is a way to make the new archive only contain the contents of
    >> "2007-10-29" and not the folders of the path leading to it?

    >
    > $ cd /Users/petermarks/Desktop/orbus/public/1/daily/
    > $ zip -r archive.zip 2007-10-29
    >
    > There's another way, but I don't remember what it is.



    Try this:

    Dir.chdir("/Users/petermarks/Desktop/orbus/public/1/daily")
    system("zip -r zipped_rails_app ./2007-10-29")
    --
    Posted via http://www.ruby-forum.com/.
    7stud --, Oct 30, 2007
    #11
  12. Peter Marks

    7stud -- Guest

    7stud -- wrote:
    >> There's another way, but I don't remember what it is.

    >
    >
    > Try this:
    >
    > Dir.chdir("/Users/petermarks/Desktop/orbus/public/1/daily")
    > system("zip -r zipped_rails_app ./2007-10-29")


    Whoops. Too late.

    --
    Posted via http://www.ruby-forum.com/.
    7stud --, Oct 30, 2007
    #12
  13. Peter Marks

    Peter Marks Guest

    7stud -- wrote:
    > 7stud -- wrote:
    >>> There's another way, but I don't remember what it is.

    >>
    >>
    >> Try this:
    >>
    >> Dir.chdir("/Users/petermarks/Desktop/orbus/public/1/daily")
    >> system("zip -r zipped_rails_app ./2007-10-29")

    >
    > Whoops. Too late.


    You were by no means too late. I was unaware that there was a ruby
    command to change the directory like that. Exactly what I needed. Thank
    you both :)
    --
    Posted via http://www.ruby-forum.com/.
    Peter Marks, Oct 30, 2007
    #13
  14. Peter Marks

    7stud -- Guest

    Peter Marks wrote:
    > 7stud -- wrote:
    >> 7stud -- wrote:
    >>>> There's another way, but I don't remember what it is.
    >>>
    >>>
    >>> Try this:
    >>>
    >>> Dir.chdir("/Users/petermarks/Desktop/orbus/public/1/daily")
    >>> system("zip -r zipped_rails_app ./2007-10-29")

    >>
    >> Whoops. Too late.

    >
    > You were by no means too late. I was unaware that there was a ruby
    > command to change the directory like that. Exactly what I needed. Thank
    > you both :)


    You could have always used system() again:

    system("cd /Users/petermarks/Desktop/orbus/public/1/daily")
    --
    Posted via http://www.ruby-forum.com/.
    7stud --, Oct 30, 2007
    #14
  15. Peter Marks

    7stud -- Guest

    7stud -- wrote:
    > You could have always used system() again:
    >
    > system("cd /Users/petermarks/Desktop/orbus/public/1/daily")
    >


    Actually, that doesn't work because the cd system() call executes in a
    separate subprocess, so the zip system() call that executes in its own
    subprocess can't see the changed directory. You need to execute both
    commands in the same subprocess, so you would have to write it like
    this:

    system("cd /Users/autie/2testing; zip -r zipped_rails_app4 ./dir3")
    --
    Posted via http://www.ruby-forum.com/.
    7stud --, Oct 30, 2007
    #15
  16. Peter Marks

    7stud -- Guest

    7stud -- wrote:
    > Actually, that doesn't work because the cd system() call executes in a
    > separate subprocess, so the zip system() call that executes in its own
    > subprocess can't see the changed directory. You need to execute both
    > commands in the same subprocess, so you would have to write it like
    > this:
    >
    > system("cd /Users/autie/2testing; zip -r zipped_rails_app4 ./dir3")
    >


    Gee whiz, I can't get anything straight tonight. In your case, it would
    be like this:

    system("/Users/petermarks/Desktop/orbus/public/1/daily"; "zip -r
    zipped_rails_app ./2007-10-29")


    --
    Posted via http://www.ruby-forum.com/.
    7stud --, Oct 30, 2007
    #16
  17. Peter Marks

    Peter Marks Guest

    7stud -- wrote:
    > You could have always used system() again:
    >
    > system("cd /Users/petermarks/Desktop/orbus/public/1/daily")


    Oh you're right. I must have done something wrong when initially trying
    that one. Thanks nonetheless.
    --
    Posted via http://www.ruby-forum.com/.
    Peter Marks, Oct 30, 2007
    #17
  18. Peter Marks

    Peter Marks Guest

    haha, well for what it's worth, I got this to work:

    system("cd #{RAILS_ROOT}/public/1/daily")
    system("zip -r 2007-10-29.zip 2007-10-29")
    --
    Posted via http://www.ruby-forum.com/.
    Peter Marks, Oct 30, 2007
    #18
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Hunsley
    Replies:
    1
    Views:
    593
    Andrew Thompson
    Sep 16, 2004
  2. Replies:
    0
    Views:
    1,713
  3. HARI OM
    Replies:
    0
    Views:
    17,401
    HARI OM
    May 3, 2005
  4. sunil_varma
    Replies:
    1
    Views:
    1,162
  5. Dave Kuhlman

    ANN: zip-ls -- Zip file listing program

    Dave Kuhlman, Jul 19, 2003, in forum: Python
    Replies:
    0
    Views:
    401
    Dave Kuhlman
    Jul 19, 2003
Loading...

Share This Page