Recursive directory scripting
Edward C. Jones
edcjones at erols.com
Tue Oct 15 10:19:36 EDT 2002
William Park wrote:
> Will Stuyvesant <hwlgw at hotmail.com> 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!
>
>
> [snipped]
If I want to do something in my current directory tree, I do:
find . > biglist
I then write a small piece of Python code that looks like:
names = open('biglist', 'r').read().splitlines()
for name in names:
if os.path.isfile(name):
do_something()
else:
do_something_else()
More information about the Python-list
mailing list