tar.py 1006 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. '''
  4. @Author : liuyuqi
  5. @Contact : liuyuqi.gov@msn.cn
  6. @Time : 2019/11/11 20:18:09
  7. @Version : 1.0
  8. @License : (C)Copyright 2019
  9. @Desc : 200个文件夹打包一次
  10. '''
  11. import os
  12. rootPath = r"/home/twtech/github/python/crawl-mrdx/data"
  13. os.chdir(rootPath)
  14. size = 100
  15. count = 1
  16. count2 = 30
  17. currentDir=""
  18. for path in os.listdir(rootPath):
  19. if os.path.isdir(os.path.join(rootPath,path)):
  20. currentDir = currentDir + " " + path
  21. if count % size == 0:
  22. shellStr = "tar -zcf /ossfs/crawl-mrdx/mrdx%s.tar.gz" % (
  23. count2) + currentDir
  24. print(shellStr)
  25. os.system(shellStr)
  26. currentDir=""
  27. count2 = count2 + 1
  28. count = count + 1
  29. # Check if there are remaining directories to include in a tar.gz file
  30. if currentDir != "":
  31. shellStr = "tar -zcf /ossfs/crawl-mrdx/mrdx%s.tar.gz" % (
  32. count2) + currentDir
  33. print(shellStr)
  34. os.system(shellStr)