recursively archiving files

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

    #1

    recursively archiving files

    Hi,

    Can I use python to recursively compress files under subdirectories
    with a certain format such as "ABC_XXX_XXX.da t" into a .gz or .zip
    file? I used to do it with "tar" on unix, but I don't like to put
    commands into a single line, as it is often more prone to error.

    Thanks
    bahoo

  • Larry Bates

    #2
    Re: recursively archiving files

    bahoo wrote:
    Hi,
    >
    Can I use python to recursively compress files under subdirectories
    with a certain format such as "ABC_XXX_XXX.da t" into a .gz or .zip
    file? I used to do it with "tar" on unix, but I don't like to put
    commands into a single line, as it is often more prone to error.
    >
    Thanks
    bahoo
    >
    Use os.walk to talk your branch of directories.
    Use glob.glob to find only those files that match your mask.
    Use zipfile or tarfile module (depending on if you want .gz or
    ..zip compressed file) to add each file to the compressed file.

    -Larry

    Comment

    Working...