recursive file editing
TaeKyon
mikalzetTogli at interfree.it
Mon Apr 5 18:22:04 EDT 2004
Il Mon, 05 Apr 2004 19:15:01 +0200, Peter Otten ha scritto:
> You need to compose the filepath, and, yes, it's a bit clumsy.
> I've written a little generator function to hide some of the clumsiness:
>
> def files(folder):
> for path, folders, files in os.walk(folder):
> for name in files:
> yield os.path.join(path, name)
>
> With that the code is simplified to:
>
> for filepath in files("/path/to/folder"):
> fileopen = file(filepath, 'r+')
> fileopen.write("This works !")
> fileopen.close()
Great !
--
Michele Alzetta
More information about the Python-list
mailing list