Solved

iterate over several subdirectories

Posted on 2004-09-16
1
429 Views
Last Modified: 2008-03-06
I need to iterate over several subdirectories and add a simple customized file to each (.htaccess).  How do I iterate through them?

thanks
je
0
Comment
Question by:jesterepsilon
1 Comment
 
LVL 9

Accepted Solution

by:
rjkimble earned 500 total points
ID: 12081221
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

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Get IP addres information from field 3 63
BASH script to modify crontab? 3 96
Getting Variable not defined error in Python 1 44
Ruby or Python 7 60
"The time has come," the Walrus said, "To talk of many things: Of sets--and lists--and dictionaries-- Of variable kinks-- And why you see it changing not-- And why so strange are strings." This part describes how variables and references (see …
A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question