recursively archiving files

B

bahoo

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
 
L

Larry Bates

bahoo said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top