sorting for recursive folder rename

Rhodri James rhodri at wildebst.demon.co.uk
Wed Dec 17 01:36:56 CET 2008


On Tue, 16 Dec 2008 18:20:52 -0000, ianaré <ianare at gmail.com> wrote:

> Hello all,
>
> I trying to recursively rename folders and files, and am looking for
> some ideas on the best way of doing this. The problem is that the
> given list of items can be in order, and one to all items may be
> renamed. Here is some preliminary code I have, but which does not work
> very well.

> self.toRename has the following structure :
> [
> [original_name, new_name, os.path.isdir]
> ..
> ]

[snip]

import os

for item in self.toRename:
     os.renames(item[0], item[1])

That's it.  os.renames will take care of all the intermediate
directory creation so you don't even need to sort the list.

-- 
Rhodri James *-* Wildebeeste Herder to the Masses



More information about the Python-list mailing list