Solved

iterate over several subdirectories

Posted on 2004-09-16
1
430 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Dictionaries contain key:value pairs. Which means a collection of tuples with an attribute name and an assigned value to it. The semicolon present in between each key and values and attribute with values are delimited with a comma.  In python we can…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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 …

726 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