Skip to main content
Solved

Get folders name with Python


danilo_fme
Evangelist
Forum|alt.badge.img+45

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? 

View original
Did this help you find an answer to your question?
<strong>This post is closed to further activity.</strong><br /> It may be a question with a best answer, an implemented idea, or just a post needing no comment.<br /> If you have a follow-up or related question, please <a href="https://community.safe.com/topic/new">post a new question or idea</a>.<br /> If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

takashi
Evangelist
  • 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
Evangelist
Forum|alt.badge.img+45
  • Author
  • Evangelist
  • 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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings