[Tutor] Dos and os.walk with Python
trs164 at hotmail.com
Fri Jan 25 01:38:13 CET 2008
Hi. I wrote a python script that goes through a specified directory and returns a list of all the files that haven't been modified since a certain date. I was hoping to be able to then continue with the program to bring up dos, and zip, then move the files (to my external hard drive). I have Windows XP. I don't know if it's okay to ask about Dos in python mailing list, so I hope it's alright. Here is my program, I don't know if there are any formatting rules for posting programs, so I hope this will sufice.import os, sys, timedef 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)) < 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 TrueI'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?g = earlierThan("G:\My Documents", 2007, ["Music"])for x in g:
os.system("COMPACT /F " + x)
os.sytem("MOVE " + x + " " + "H:\Backup")Thanks
Need to know the score, the latest news, or you need your Hotmail®-get your "fix".
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor