Extra Newby question - Trying to create md5 File Listing

J

James Johnston

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.
 
D

Dennis Lee Bieber

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')

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
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
D

Dennis Lee Bieber

Offhand, your "filelist" is NOT just files, but seems to be path
parts.... That "c" looks suspiciously like the "c" from "c:\"

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

A list of files
filelist = ["c:\\some.file", "d:\\another.file"]
for fn in filelist:
.... 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
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
J

Jim

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top