[Tutor] Dos and os.walk with Python

Timothy Sikes trs164 at hotmail.com
Fri Jan 25 02:28:18 CET 2008

I'm getting the "Digest" version of the mailing list, if there's any better way to respond to a specific message, I would like to know. thanks :>

> From: tutor-request at python.org> Subject: Tutor Digest, Vol 47, Issue 66> To: tutor at python.org> Date: Fri, 25 Jan 2008 02:09:13 +0100> > ------------------------------> > Message: 9> Date: Fri, 25 Jan 2008 01:11:00 -0000> From: "Alan Gauld" <alan.gauld at btinternet.com>> Subject: Re: [Tutor] Dos and os.walk with Python> To: tutor at python.org> Message-ID: <fnbcrb$4ae$1 at ger.gmane.org>> Content-Type: text/plain; format=flowed; charset="iso-8859-1";> reply-type=original> > > "Timothy Sikes" <trs164 at hotmail.com> wrote> > > I don't know if it's okay to ask about Dos in python mailing list,> > If its related to programming in python as well its fine :-)> > > I don't know if there are any formatting rules for posting programs> > It helps if we can see the formatting, especially since Python> relies on layout. This was just a mess on my screen!> > I've tried to sort it out...
I can't seem to figure out how to make hotmail keep those spaces and new lines.....   ah oh well
> > ---------------------------------------> import os, sys, time> > def earlierThan (path, year, exclude=[]):> all = []> walk = os.walk(path)> for root, dirs, files in walk:> for i in files:> try:> if (time.localtime(os.path.getmtime(root + "\\" + > i))[0] < year> and doesNotHave(exclude, root)) :> all.append(root + "\\" + i)> except OSError:> #I think that I might need a more specific error > message,> #as this one would handle something> #That's not necessarily a broken file name. (I got > one of them when I ran it).> print root + "\\" + i + " was not included in the > list"> return all> > def doesNotHave(exclude, root):> for x in exclude:> if root.startswith(x) > -1:> return False> return True> ----------------------------------------------> > That last function is a little odd. startswith already returns> a boolean so comparing to -1 is weird. I'm not sure what> you think it will do.
yeah, I meant to have it as .find()
> > Consider:> > >>> 'fred'.startswith('x')> False> >>> 'fred'.startswith('x') > -1> True> >>> 'fred'.startswith('f') > -1> True> >>>> > I'm not sure when it would ever fail the test so I think your> function will nearly always return False.> > > I've had little experience with dos. I believe I should use the> > COMPACT, and then the MOVE dos command... Would> > it go something like this?> > You could use these but you'd be better just using Python> to do it via the shutil and os modules and avoid the DOS> commands completely IMHO.> 
Okay, I've found the move command from the shutil module,  but I don't see one that compressess files...  Are there some? or am I just not seeing them...thanks.> HTH,> > > -- > Alan Gauld> Author of the Learn to Program web site> http://www.freenetpages.co.uk/hp/alan.gauld > > > > > ------------------------------> > _______________________________________________> Tutor maillist - Tutor at python.org> http://mail.python.org/mailman/listinfo/tutor> > > End of Tutor Digest, Vol 47, Issue 66> *************************************
Helping your favorite cause is as easy as instant messaging. You IM, we give.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080124/9ad2b6a9/attachment.htm 

More information about the Tutor mailing list