In psudocode:<br><br>#map the files to their time.<br>filesByTimes = {}<br>for each in filesInDirectory:<br>&nbsp;&nbsp;&nbsp;&nbsp; filesByTimes[os.stat(each).st_mtime]=each<br><br>#find the largest time<br>times = filesByTimes.keys()<br>sort(times)
<br><br>#retrieve the file that goes with it<br>latestFile = filesByTimes[times[-1]]<br><br><br>&nbsp;&nbsp; --Michael<br><br><br><div><span class="gmail_quote">On 11/5/07, <b class="gmail_sendername">Fiyawerx</b> &lt;<a href="mailto:fiyawerx@gmail.com">
fiyawerx@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I&#39;m working on a small script that so far, using the xlrd module, (
<a href="http://www.lexicon.net/sjmachin/xlrd.html" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.lexicon.net/sjmachin/xlrd.html</a>) will parse all the files in a given directory for a xls file with a specific worksheet. This way, if the file names change, or people don&#39;t save the spreadsheet with the right name, my script will still be able to locate the correct files to use for it&#39;s data source out of multiple files / versions. So far what I have sort of goes like this :
<br><br>import os<br>import xlrd<br><br>data = {}<br><br>#path may be set externally at some point<br>data[&#39;path&#39;] = &#39;mypath_to_program&#39;<br><br>os.chdir(data[&#39;path&#39;])<br><br>data[&#39;xls_files&#39;] = [ file for file in 
os.listdir(&#39;./&#39;) if &#39;.xls&#39; in file ]<br><br>first_files = [ file for file in data[&#39;xls_files&#39;] if u&#39;First Worksheet&#39; in xlrd.open_workbook(file).sheet_names() ]<br>data[&#39;first_file&#39;] = ??
<br><br>second_files = [ file for file in  data[&#39;xls_files&#39;] if u&#39;Second Worsheet&#39; in xlrd.open_workbook(file).sheet_names() ]<br>data[&#39;second_file&#39;] = ??<br><br>This is where I get stuck, I&#39;m trying to figure out how, from the files
that match, I can select the file with the most current time stamp and
use that as my main data file.<br>I know I can get the modification time with os.stat(file).st_mtime, but I&#39;m not sure how I can sort my returns by this, to get just the most current version. Any help / thoughts would be appreciated. I&#39;m going to be looking for other worksheets as well that might be in
other xls&#39;s, for example &#39;Second Worksheet&#39; also, but I was just trying to get the &#39;first_files&#39; working first. Instead of opening them each time, should I construct some type of data that stores the file, it&#39;s worksheets, and its modification times for each file found, and then just parse that list? like maybe change my xls_files around to not just be a list of names?
<br>
<br>_______________________________________________<br>Tutor maillist &nbsp;- &nbsp;<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:Tutor@python.org">Tutor@python.org</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">
http://mail.python.org/mailman/listinfo/tutor</a><br><br></blockquote></div><br><br clear="all"><br>-- <br>Michael Langford<br>Phone: 404-386-0495<br>Consulting: <a href="http://www.TierOneDesign.com/">http://www.TierOneDesign.com/
</a>