Solved

iterate over several subdirectories

Posted on 2004-09-16
1
425 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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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. …
Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now