Compressing folders in Windows using Python.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sri2097

    #1

    Compressing folders in Windows using Python.

    Hi,
    I'm trying to zip a particular fiolder and place the zipped folder into
    a target folder using python. I have used the following command in
    'ubuntu'.

    zip_command = 'zip -qr %s %s' % (target, ' '.join(source))

    I execute this using os.command(zip_ command). It works fine...

    But when I run this script in Windows XP, I get an error while
    executing the above zip command. What command is there to zip files in
    Windows? Or is there any other problem ?

  • Steven D'Aprano

    #2
    Re: Compressing folders in Windows using Python.

    On Sun, 01 Jan 2006 04:07:11 -0800, sri2097 wrote:
    [color=blue]
    > Hi,
    > I'm trying to zip a particular fiolder and place the zipped folder into
    > a target folder using python. I have used the following command in
    > 'ubuntu'.
    >
    > zip_command = 'zip -qr %s %s' % (target, ' '.join(source))
    >
    > I execute this using os.command(zip_ command). It works fine...
    >
    > But when I run this script in Windows XP, I get an error while
    > executing the above zip command.[/color]

    Would you like to tell us what error you get?

    No no, I'll just guess... your disk is full... am I close?

    *wink*
    [color=blue]
    > What command is there to zip files in Windows? Or is there any other problem ?[/color]

    What happens if you call up a Windows command prompt and type zip at the
    prompt?



    --
    Steven.

    Comment

    • Heiko Wundram

      #3
      Re: Compressing folders in Windows using Python.

      Steven D'Aprano wrote:[color=blue][color=green]
      >> But when I run this script in Windows XP, I get an error while
      >> executing the above zip command.[/color]
      >
      > Would you like to tell us what error you get?[/color]

      I presume the error he's seeing is something along the line of:

      "zip: Bad command or filename."

      That's basically because there is no commandline builtin for zipping up
      files on Windows, and I don't know of WinZIP or any of the InfoZIP derived
      GUIs installing a command-line zipper.

      What might help you though (and keep you platform-independent):



      --- Heiko.

      Comment

      • Heiko Wundram

        #4
        Re: Compressing folders in Windows using Python.

        Heiko Wundram wrote:[color=blue]
        > That's basically because there is no commandline builtin for zipping up
        > files on Windows, and I don't know of WinZIP or any of the InfoZIP derived
        > GUIs installing a command-line zipper.[/color]

        btw. the zip command isn't builtin on Unix either. It's only available if
        you installed the corresponding InfoZIP package(s). I know pretty much
        every Linux-distribution comes preinstalled with it (because of stuff like
        ark, a KDE-frontend for archivers, requiring it), but you shouldn't rely on
        that either.

        --- Heiko.

        Comment

        • bren[at]gillatt.org

          #5
          Re: Compressing folders in Windows using Python.

          Heiko Wundram wrote:[color=blue]
          > Steven D'Aprano wrote:
          >[color=green][color=darkred]
          >>>But when I run this script in Windows XP, I get an error while
          >>>executing the above zip command.[/color]
          >>
          >>Would you like to tell us what error you get?[/color]
          >
          >
          > I presume the error he's seeing is something along the line of:
          >
          > "zip: Bad command or filename."
          >
          > That's basically because there is no commandline builtin for zipping up
          > files on Windows, and I don't know of WinZIP or any of the InfoZIP derived
          > GUIs installing a command-line zipper.
          >
          > What might help you though (and keep you platform-independent):
          >
          > http://www.python.org/doc/2.4.2/lib/module-zipfile.html
          >
          > --- Heiko.[/color]

          Go and get something like 7-ZIP and put a path environment variable in.

          Comment

          • Christian Tismer

            #6
            Re: Compressing folders in Windows using Python.

            sri2097 wrote:[color=blue]
            > Hi,
            > I'm trying to zip a particular fiolder and place the zipped folder into
            > a target folder using python. I have used the following command in
            > 'ubuntu'.
            >
            > zip_command = 'zip -qr %s %s' % (target, ' '.join(source))
            >
            > I execute this using os.command(zip_ command). It works fine...
            >
            > But when I run this script in Windows XP, I get an error while
            > executing the above zip command. What command is there to zip files in
            > Windows? Or is there any other problem ?[/color]

            zip is not a built-in command for windows.
            You might use winzip or something else, there is
            a bunch of different compression tools available.

            ciao - chris

            --
            Christian Tismer :^) <mailto:tismer@ stackless.com>
            tismerysoft GmbH : Have a break! Take a ride on Python's
            Johannes-Niemeyer-Weg 9A : *Starship* http://starship.python.net/
            14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
            work +49 30 802 86 56 mobile +49 173 24 18 776 fax +49 30 80 90 57 05
            PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04
            whom do you want to sponsor today? http://www.stackless.com/

            Comment

            • Tim N. van der Leeuw

              #7
              Re: Compressing folders in Windows using Python.


              Christian Tismer wrote:[color=blue]
              > sri2097 wrote:[color=green]
              > > Hi,
              > > I'm trying to zip a particular fiolder and place the zipped folder into
              > > a target folder using python. I have used the following command in
              > > 'ubuntu'.
              > >
              > > zip_command = 'zip -qr %s %s' % (target, ' '.join(source))
              > >
              > > I execute this using os.command(zip_ command). It works fine...
              > >
              > > But when I run this script in Windows XP, I get an error while
              > > executing the above zip command. What command is there to zip files in
              > > Windows? Or is there any other problem ?[/color]
              >
              > zip is not a built-in command for windows.
              > You might use winzip or something else, there is
              > a bunch of different compression tools available.
              >
              > ciao - chris
              >[/color]

              Something else to watch for -- Spaces in filenames. Uncommon on
              unix/linux, but very common on windows. Put some double-quotes around
              the filenames in your zip_command:

              zip_command = 'zip -qr "%s" "%s"' % (target, ' '.join(source))


              AFAIK there are built-in zip modules available in Python? They might be
              a better alternative to calling an external zip command?

              (Winzip btw, has a seperate download for a command-line capable version
              of the compressor)

              cheers,

              --Tim

              [color=blue]
              > --
              > Christian Tismer :^) <mailto:tismer@ stackless.com>
              > tismerysoft GmbH : Have a break! Take a ride on Python's
              > Johannes-Niemeyer-Weg 9A : *Starship* http://starship.python.net/
              > 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
              > work +49 30 802 86 56 mobile +49 173 24 18 776 fax +49 30 80 90 57 05
              > PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04
              > whom do you want to sponsor today? http://www.stackless.com/[/color]

              Comment

              Working...