I am programming a folder synchronizer for my first python project.
(I want to get it finished before school starts in about 2 months. heh heh)
Anyway, up till now my synchronizer will only copy file from one folder to another.
I want it to be able to copy entire sub folders but I don't know how to list the sub folders of a given folder using python code.
That's my QUESTION:
how do i list the sub folders of a directory?

Recommended Answers

All 4 Replies

I am programming a folder synchronizer for my first python project.
(I want to get it finished before school starts in about 2 months. heh heh)
Anyway, up till now my synchronizer will only copy file from one folder to another.
I want it to be able to copy entire sub folders but I don't know how to list the sub folders of a given folder using python code.
That's my QUESTION:
how do i list the sub folders of a directory?

Use the os.walk or the os.path.walk function (prefer the first one as this one is removed from python 3.0)

There's also os.listdir.

In order to use os.listdir you would also want to combine it with os.path.isdir since you'll receive a list of both file and directory names.

wow.. thanks.
everyone's suggestions were equally useful

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.