Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a directory containing 450 folders, all unique names. Inside this folder I need to create a sub-folder called Metadata, so it looks like the following: Folder1/Metadata Folder2/Metadata Folder3/Metadata

Is there a way using Python to create this example?

share|improve this question
You can create a folder with os.makedir(path). See the docs for more information. – camelNeck Mar 28 at 10:23

closed as not a real question by bensiu, Mark, mdm, ecatmur, Zenith Mar 28 at 13:51

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

1 Answer

The functions you are looking for are all in the os module:

import os
for item in os.listdir('.'):
    if os.path.isdir(item):
        newdir = os.path.join(item, 'Metadata')
        if not os.path.exists(newdir):
            os.makedirs(newdir)
share|improve this answer
1  
I guess directories are not recursive as per the details, so mkdir should also work. – Ankit Jaiswal Mar 28 at 10:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.