Recursive directory scripting

William Park opengeometry at
Tue Oct 15 06:24:18 CEST 2002

Will Stuyvesant <hwlgw at> wrote:
> Often I have to do something in the current directory and
> recursively below.  Like cleaning up.  Can I use python
> for this?  Yes I can, the scripts are below.  I tried to
> make it portable so it would also work with linux, but I
> gave up.  Maybe you can?
> Improvements and other comments are welcome!


> With 'C:\bin' added to my %PATH% and walkcommand.bat and
> there I can now clean my directory and any
> directories below like this: 
> C:\doc> walkcommand del *.aux *.toc *.log *.*~ *~ *.bak
> Of course it is saver to put 'del *.aux *.toc *.log *.*~
> *~ *.bak' in a file called clean.bat in C:\bin and do:
> C:\doc> walkcommand clean

On Linux, you would just do
    find -type d | while read i; do
	(cd $i; rm *.aux *.toc *.log *.*~ *~ *.bak)
    find -type f -name '*.aux' | xargs rm
    find -type f -name '*.toc' | xargs rm
    find -type f -name '*~'    | xargs rm
    find -type f -name '*.bak' | xargs rm

No need for convoluted script on script.

William Park, Open Geometry Consulting, <opengeometry at>
Linux solution for data processing and management

More information about the Python-list mailing list