Skip to content

Instantly share code, notes, and snippets.

@serian
Created February 2, 2011 17:35
Show Gist options
  • Save serian/808041 to your computer and use it in GitHub Desktop.
Save serian/808041 to your computer and use it in GitHub Desktop.
python tar.gz
import tarfile
tgzfile = tarfile.open(tgz_name,'w:gz')
cp_dir = os.path.join(tgt_dir, cp_dir_name)
if not os.exists(cp_dir):
os.mkdir(cp_dir)
for k, v in sorted(tgt_xml_dct.items(), key=lambda x:x[1]):
tgzfile.add(k, os.path.join(cp_dir_name, os.path.basename(k)))
shutil.copy(k, cp_dir)
tgzfile.close()
@serian
Copy link
Author

serian commented Feb 2, 2011

addメソッドで格納する時のディレクトリ構造を指定

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment