In <[EMAIL PROTECTED]>, rbt wrote:
Do you need to compare dictionaries, if its an option it would be simpler/cheaper to compare each entry from your file listing with entries in a single dict and act accordingly, mainly because you will already have built your path/date pairs from your dir listing, adding them to a dict purely for comparison is an extra step.
import os
new_files = [ ]
changed = [ ]
listing = os.listdir('c:/python24')
for a_file in listing:
f_date = os.path.getmtime(os.path.join('c:/python24' , a_file))
try
if mydict[a_file] != f_date:
changed.append(a_file)
except:
new_files.append(a_file)
mydict[a_file] = f_date
deleted = [ key for key in mydict if not key in listing ]
for x in deleted:
del mydict[x]
print changed
print new_files
print deleted
HTH :)
> What's a good way to compare values in dictionaries?
Do you need to compare dictionaries, if its an option it would be simpler/cheaper to compare each entry from your file listing with entries in a single dict and act accordingly, mainly because you will already have built your path/date pairs from your dir listing, adding them to a dict purely for comparison is an extra step.
import os
new_files = [ ]
changed = [ ]
listing = os.listdir('c:/python24')
for a_file in listing:
f_date = os.path.getmtime(os.path.join('c:/python24' , a_file))
try
if mydict[a_file] != f_date:
changed.append(a_file)
except:
new_files.append(a_file)
mydict[a_file] = f_date
deleted = [ key for key in mydict if not key in listing ]
for x in deleted:
del mydict[x]
print changed
print new_files
print deleted
HTH :)
-- http://mail.python.org/mailman/listinfo/python-list