Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Input can be individual files, and/or folders. Use * (any string), ? (one charac
Options:

- `--addcrc`: Adds CRC to filenames
- `--updatecrc`: Updates CRC to filenames
- `-c out.sfv` or `--createsfv out.sfv`: Creates a SFV file
- `-r` or `--recursive`: Also includes sub-folder
- `-s` or --searchsubfolder : Also search sub-folder for matching filenames
Expand Down
22 changes: 18 additions & 4 deletions python_crc32_hasher.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
import sys, os, zlib, hashlib, shutil, re, time, struct, multiprocessing, math

programName = "Python CRC-32 Hasher"
version = "1.9"
version = "1.10"
author = "dreamer2908"
contributors = ["felipem775"]

addcrc = False
updatecrc = False
force = False
recursive = False
searchSubFolder = False
Expand Down Expand Up @@ -221,7 +223,7 @@ def processFile(fileName, fromFolder = False):
elif sHash in fileName.upper():
result = "File OK!"
st_ok += 1
elif found:
elif found and not updatecrc:
result = "File not OK! %s found in filename." % crc
st_notok += 1
else:
Expand All @@ -234,6 +236,15 @@ def processFile(fileName, fromFolder = False):
except:
result = "Renaming failed!"
newName = fileName
elif updatecrc:
namae, ext = os.path.splitext(fileName)
newName = namae.replace(crc,sHash) + ext
try:
shutil.move(fileName, newName)
result = "CRC updated!"
except Exception as e:
result = "Renaming failed!"
newName = fileName
else:
result = "CRC not found!"
st_notfound += 1
Expand Down Expand Up @@ -455,7 +466,7 @@ def removeNonAscii(original):

# Parse paramenters
def parseParams():
global pathList, addcrc, createsfv, sfvPath, force, recursive, searchSubFolder, showChecksumResult, showFileInfo, showFullPath
global pathList, addcrc, updatecrc, createsfv, sfvPath, force, recursive, searchSubFolder, showChecksumResult, showFileInfo, showFullPath
global enableMd5, enableSha1, enableSha256, enableSha512, enableEd2k, enableCrc, enableAll, enableMd4
global debug, waitBeforeExit

Expand All @@ -469,6 +480,8 @@ def parseParams():

if arg == "addcrc":
addcrc = True
elif arg == "updatecrc":
updatecrc = True
elif arg == "createsfv" and i < len(sys.argv) - 1:
createsfv = True
sfvPath = sys.argv[i+1]
Expand Down Expand Up @@ -606,6 +619,7 @@ def printReadme():
print(" Use Unix shell-style wildcard (*, ?) for the filename pattern.\n")
print("Options:")
print(" --addcrc Add CRC-32 to filenames.")
print(" --updatecrc Update CRC-32 to filenames.")
print(" -c | --createsfv out.sfv Create a SFV file.")
print(" -r | --recursive Also include sub-folder.")
print(" -s | --searchsubfolder Also search sub-folder for matching filenames.")
Expand Down Expand Up @@ -705,4 +719,4 @@ def doStuff():
initStuff()
parseParams()
checkSanity()
doStuff()
doStuff()