iterate over several subdirectories

I need to iterate over several subdirectories and add a simple customized file to each (.htaccess).  How do I iterate through them?

thanks
je
jesterepsilonAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
rjkimbleConnect With a Mentor Commented:
if subdirs is list of subdirectories, you can try this:

import os, os.path
for subdir in subdirs:
    for dirpath, dirnames, filenames in os.walk( subdir ):
        print os.path.join( dirpath, '.htaccess' )

Just replace the print statement with one that creates your customized file. Be sure to check the documentation notes about symbolic links if that's a concern in your situation.

0
All Courses

From novice to tech pro — start learning today.