<br><br><div><span class="gmail_quote">On 30/12/05, <b class="gmail_sendername">rbt</b> <<a href="mailto:rbt@athop1.ath.vt.edu">rbt@athop1.ath.vt.edu</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
What's a good way to compare values in dictionaries? I want to find<br>[snip]<br>My key-values pairs are filepaths and their modify times. I want to<br>identify files that have been updated or added since the script last ran.
</blockquote><div><br>
You don't need to store each file's updated time, you only need to
store the last time you ran the script and to compare each file's
modified time against that last-run time.   Dictionaries
aren't required<br>
<br>
eg:<br>
<br>
 #    to get files changed (added/modified) since a given date<br>
import time, os<br>
last_run = time.time() - (60*60*24*30*12)   # for testing, set to one year ago<br>
changed = [x for x in  os.listdir('c:/python24') if os.path.getmtime(os.path.join('c:/python24' , x)) > last_run]<br>
# script end<br>
<br>
>From your previous posts, I believe you are storing details of *every*
file  within a dictionary that is pickled to your hard disk, 
then periodically creating a new dict  of *every* file and
comparing it against the original dict.   Then you must be
updating the original dict with the new times and storing it back to
disk.   The above list comprehension will give the same
result for files/dirs in a single directory,  you just need to
store the time of the last script run to disk instead.<br>
<br>
if you are walking several directories, the principle is the same,<br>
<br>
>>> last_run = time.time() - (60*60*24*30)  # 1 month ago<br>
>>> for root, dirs, files in os.walk('c:/python24'):<br>
...     for name in files:<br>
...         if os.path.getmtime(os.path.join(root , name)) > last_run:<br>
...             print os.path.join(root , name)<br>
...             <br>
c:/python24\Lib\asynchat.pyc<br>
c:/python24\Lib\calendar.pyc<br>
c:/python24\Lib\gzip.pyc<br>
c:/python24\Lib\imghdr.pyc<br>
c:/python24\Lib\SimpleHTTPServer.pyc<br>
c:/python24\Lib\sndhdr.pyc<br>
c:/python24\Lib\webbrowser.pyc<br>
c:/python24\Lib\_strptime.pyc<br>
c:/python24\Lib\email\MIMEAudio.pyc<br>
c:/python24\Lib\email\MIMEImage.pyc<br>
c:/python24\Lib\email\MIMEMessage.pyc<br>
c:/python24\Lib\email\MIMEMultipart.pyc<br>
>>><br>
<br>
<br>
<br>
</div><br></div>