recursive file editing
Josiah Carlson
jcarlson at uci.edu
Sat Apr 3 17:07:42 EST 2004
> I'm a python newbie; here are a few questions relative to a
> problem I'm trying to solve; I'm wandering if python is the best
> instrument or if awk or a mix of bash and sed would be better:
>
> 1) how would I get recursively descend
> through all files in all subdirectories of
> the one in which my script is called ?
Check out os.path.walk.
> 2) each file examined should be edited; IF a string of this type is found
>
> foo.asp=dev?bar (where bar can be a digit or an empty space)
>
> it should always be substituted with this string
>
> foo-bar.html (if bar is an empty space the new string is foo-.html)
Check out the re module.
> 3) the names of files read may themselves be of the sort foo.asp=dev?bar;
> the edited output file should also be renamed according to the same rule
> as above ... or would this be better handled by a bash script ?
Do it however you feel more comfortable, Python can do it.
- Josiah
More information about the Python-list
mailing list