The way I'd do it is create a dict mapping extensions to folders (something like {'doc': 'word', 'pdf': 'acrobat'} ), then use os.renames(old, new), which works the same as moving when you give it a different path for new, and also magically handles creating new directories for you. The documentation for the os.walk() contains an example that could easily be modified to do what you want.
The documentation is your friend. > Message: 8 > Date: Thu, 18 Sep 2008 08:50:58 +0100 > From: "Alan Gauld" <[EMAIL PROTECTED]> > Subject: Re: [Tutor] recursive using the os.walk(path) from the os > module > To: tutor@python.org > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; format=flowed; charset="iso-8859-1"; > reply-type=original > > > "A. Joseph" <[EMAIL PROTECTED]> wrote > >> I want to search through a directory and re-arrange all the files >> into e.g >> >> All .doc files go into MS WORD folder, all .pdf files goes into PDF >> Folder. >> >> I`m thinking of doing something with the os.walk(path) method from >> os > > Which aspect is puzzling you? The use of os walk to traverse the > folders? Or the algorithm to put the files into new folders? > > In either case you might get the answer in my Using the OS topic in > my tutorial. > > Otherwise try posting a bit more detail on what you need. > > Thanks, > > -- > Alan Gauld > Author of the Learn to Program web site > http://www.freenetpages.co.uk/hp/alan.gauld > > > > > ------------------------------ > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > End of Tutor Digest, Vol 55, Issue 56 > ************************************* > -- Richard "Roadie Rich" Lovely, part of the JNP|UK Famile www.theJNP.com _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor