Created
November 22, 2020 16:23
-
-
Save rob5300/a4b1e7207f83fe4bd09d1af075875215 to your computer and use it in GitHub Desktop.
BZip each file into its own archive and save into new folder structure. Useful for Source/TF2 server files to download
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# BZipAll script to quickly bzip all files in a directory. | |
# Made by rob5300 | |
# FILL ME IN!!! THIS MAY NOT BE RIGHT FOR YOU!! | |
# Full path to your 7z.exe executable from your 7z install. Plz download or install it if you need from 7-zip.org | |
_7zpath = r"C:\Program Files\7-Zip\7z.exe" | |
#Extensions to ignore | |
ignore = [".py", ".sp", ".smx", ".bz2"] | |
#====================================================== | |
import os | |
import sys | |
import subprocess | |
dir_path = os.path.dirname(os.path.realpath(__file__)) | |
compressed_path = os.path.join(dir_path, "bzipped") | |
def ListDir(relativePath): | |
path = os.path.join(dir_path, relativePath) | |
print(f"Looking inside {path}") | |
for file in os.listdir(path): | |
fullpath = os.path.join(path, file) | |
print(f"Checking {fullpath}") | |
if os.path.isdir(fullpath): | |
ListDir(os.path.join(relativePath, file)) | |
else: | |
BZipFile(os.path.join(relativePath, file)) | |
def BZipFile(relativeFilePath): | |
for ext in ignore: | |
if ext in relativeFilePath: | |
return | |
name = os.path.basename(relativeFilePath) | |
file = os.path.join(dir_path, relativeFilePath) | |
originaldir = os.path.dirname(file) | |
destPath = os.path.dirname(os.path.join(compressed_path, relativeFilePath)) | |
print(f"=== Making bz2 for filepath: {relativeFilePath}. Dest: {destPath}") | |
subprocess.call([_7zpath, "a", os.path.join(destPath, name + '.bz2'), file]) | |
#bzipcmd = f"\"{_7zpath}\" a \"{os.path.join(destPath, name + '.bz2')}\" \"{file}\"" | |
print("=== Making bzip done.") | |
if not os.path.exists(compressed_path): | |
print("Making bzipped dir") | |
os.mkdir(compressed_path) | |
ListDir("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment