Connecting Tech Pros Worldwide Help | Site Map

recursively archiving files

bahoo
Guest
 
Posts: n/a
#1: Apr 9 '07
Hi,

Can I use python to recursively compress files under subdirectories
with a certain format such as "ABC_XXX_XXX.dat" 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
Guest
 
Posts: n/a
#2: Apr 9 '07

re: recursively archiving files


bahoo wrote:
Quote:
Hi,
>
Can I use python to recursively compress files under subdirectories
with a certain format such as "ABC_XXX_XXX.dat" 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
Closed Thread