Extra Newby question - Trying to create md5 File Listing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • James Johnston

    Extra Newby question - Trying to create md5 File Listing


    I've never written a Python program before and I'm trying to read a config
    file with file path/names (eg. c:\\python24\\* .dll, ... *.exe) to create an
    output file of filename + md5 values. I'm confused. I'm trying to learn
    how to use Wing IDE and step through the Stack Data. It seems to be
    working but on the
    for fn in filelist:
    data = file(fn,'rb').r ead()

    I get a
    IOError: (2, 'No such file or directory', 'c')

    Traceback (innermost last):

    File "c:\Python examples\md5mak r_test4.py", line 1, in ?
    #!/usr/bin/python
    File "c:\Python examples\md5mak r_test4.py", line 20, in ?
    data = file(fn,'rb').r ead()

    Code:
    #!/usr/bin/python
    # Filename: md5makr_test4.p y

    import sys, os, os.path, glob, md5, ConfigParser

    config = ConfigParser.Co nfigParser()
    config.read('md 5makr.ini')

    outputfilname = config.get('gen eral', 'outputfile')
    f = file(outputfiln ame,'wt')
    fileconfig = config.get('gen eral', 'inputfiles')

    fl = file(fileconfig ,'r')
    fileData = fl.read()

    for f1 in glob.glob(fileD ata):
    filelist = f1

    for fn in filelist:
    data = file(fn,'rb').r ead()
    hexstring = md5.md5(data).h exdigest()
    f.write(fn + '\t' + hexstring + '/n')

    f.close()

    Any insight or help would be appreciated.


  • Jim

    #2
    Re: Extra Newby question - Trying to create md5 File Listing

    Thanks Dennis, I'm feeling very stupid. You're right about the config
    file containing drive/path/filenames (eg. c:\python24\*.e xe or
    whatever). I want to output a text file that contains records like
    c:\python24\pyt honw.exe[tab]md5 value, ... next file record. The
    following snippet works but I don't know how to loop through using the
    config value to get e glob for each file. I'll keep working at it.

    filelist = glob.glob('c:\\ python24\\*.exe ')

    # print 'filelist is', filelist

    for fn in filelist:
    data = file(fn,'rb').r ead()
    hexstring = md5.md5(data).h exdigest()
    f.write(fn + '\t' + hexstring + '\n')

    f.close()

    Thanks.

    Comment

    Working...