Extra Newby question - Trying to create md5 File Listing

Discussion in 'Python' started by James Johnston, Sep 27, 2006.

  1. 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').read() ​

    I get a

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

    Traceback (innermost last):

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

    Code:
    #!/usr/bin/python
    # Filename: md5makr_test4.py

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

    config = ConfigParser.ConfigParser()
    config.read('md5makr.ini')

    outputfilname = config.get('general', 'outputfile')
    f = file(outputfilname,'wt')
    fileconfig = config.get('general', 'inputfiles')

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

    for f1 in glob.glob(fileData):
    filelist = f1

    for fn in filelist:
    data = file(fn,'rb').read()
    hexstring = md5.md5(data).hexdigest()
    f.write(fn + '\t' + hexstring + '/n')

    f.close()

    Any insight or help would be appreciated.
     
    James Johnston, Sep 27, 2006
    #1
    1. Advertisements


  2. Offhand, your "filelist" is NOT just files, but seems to be path
    parts.... That "c" looks suspiciously like the "c" from "c:\"
    --
    Wulfraed Dennis Lee Bieber KD6MOG

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
     
    Dennis Lee Bieber, Sep 27, 2006
    #2
    1. Advertisements

  3. OR, as I just realized... Your "filelist" is NOT a list of files,
    but a string from your config file...

    A list of files
    .... print fn
    ....
    c:\some.file
    d:\another.file

    A string from some other file.... print fn
    ....
    c <<<<<<<<<<
    :
    \
    s
    o
    m
    e
    ..
    f
    i
    l
    e
    ,
    --
    Wulfraed Dennis Lee Bieber KD6MOG

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
     
    Dennis Lee Bieber, Sep 27, 2006
    #3
  4. James Johnston

    Jim Guest

    Thanks Dennis, I'm feeling very stupid. You're right about the config
    file containing drive/path/filenames (eg. c:\python24\*.exe or
    whatever). I want to output a text file that contains records like
    c:\python24\pythonw.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').read()
    hexstring = md5.md5(data).hexdigest()
    f.write(fn + '\t' + hexstring + '\n')

    f.close()

    Thanks.
     
    Jim, Sep 27, 2006
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.