Advertisement
Guest User

Untitled

a guest
Feb 8th, 2020
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import zipfile
  4. import rarfile
  5. from os import listdir
  6. from os.path import isfile, join
  7. filePathToZips = "C:\\Users\\OscarAndersson\\Desktop\\script\\"
  8.  
  9. def checkRar(file, filePath):
  10.   rf = rarfile.RarFile(filePath)
  11.   for rarItem in rf.infolist():
  12.     checkFileEndingIsObj(rarItem.filename, filePath)
  13.  
  14. def checkZip(file, filePath):
  15.   zipArchive = zipfile.ZipFile(filePath, 'r')
  16.   for zipItem in zipArchive.infolist():
  17.     checkFileEndingIsObj(zipItem.filename, filePath)
  18.  
  19. def checkFileEndingIsObj(fileName, filePath):
  20.   if fileName.endswith('.OBJ') or fileName.endswith('.obj'):
  21.     try:
  22.       completePath = join(filePathToZips, fileName)
  23.       open(completePath, "x")
  24.     except FileExistsError:
  25.       print('File already exists')
  26.  
  27.  
  28. onlyfiles = [f for f in listdir(filePathToZips) if isfile(join(filePathToZips, f))]
  29. for file in onlyfiles:
  30.   filePath = filePathToZips + file
  31.   if file.endswith('.zip'):
  32.     checkZip(file, filePath)
  33.   elif file.endswith('.rar'):
  34.     checkRar(file, filePath)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement