how can generate crc32 from files in directory to save in a file

0

I would like to generate a crc32 from all files and write it together with the file name into a file

I use the script so far:

import glob, os, sys, re, shutil, zlib

path = 'P:\dn\test55'
wrname = r'P:\dn\path\test55.txt'
test_files = [f for f in os.listdir(path) if f.endswith('.mp3')]
checksum = crc(test_files)
f = open(wrname, "w")
f.write("\n".join(test_files, checksum ))
f.close()




def crc(a_file_name):
prev = 0
for eachLine in open(a_file_name,"rb"):
    prev = zlib.crc32(eachLine, prev)
return "%X"%(prev & 0xFFFFFFFF)


def main():
checksum = crc(file_name)
print(checksum, file_name)

I tried to derive from it:

https://wiki-bsse.ethz.ch/display/DBSSEQGF/Calculating+CRC32+checksum+with+Python

error ist in my script:

NameError: name 'crc' is not defined

I want the file test55.txt to look like this:

001-file.mp3 e4009ec3
002-file.mp3 687bb62b
003-file.mp3 cc185cee

what's wrong with that

thanks :)

python-3.x
asked on Stack Overflow Apr 4, 2020 by kuck

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0