Skip to main content
Solved

Get folders name with Python

  • January 5, 2016
  • 2 replies
  • 15 views

danilo_fme
Celebrity
Forum|alt.badge.img+52

Hello all,

I have a Folder with subfolders:

How can i get the names subfolder with python?

Thanks in Advance,

Best answer by takashi

An example.

>>> import os
>>> root = 'C:/Data'
>>> for file in os.listdir(root):
...     if os.path.isdir('%s/%s' % (root, file)):
...         print file

"os.walk" can also be used. See also the Python documentation.

BTW, why not use the PATH reader? 

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

takashi
Celebrity
  • Best Answer
  • January 5, 2016

An example.

>>> import os
>>> root = 'C:/Data'
>>> for file in os.listdir(root):
...     if os.path.isdir('%s/%s' % (root, file)):
...         print file

"os.walk" can also be used. See also the Python documentation.

BTW, why not use the PATH reader? 


danilo_fme
Celebrity
Forum|alt.badge.img+52
  • Author
  • Celebrity
  • January 5, 2016

Hello @takashi thanks your help. It was very important. :)

The reason that i don`t use the Path Reader on this case, is because i use in my workspace the Shutdown Python.

Thanks agian,

Danilo