Any way to tell if there are folders (sub directories) in current directory?

I’m working on a script that will auto change the icon display in the file browser if it detects items (such as blend files or images) with generated thumbnails but will switch the icon display back to short list once leaving the file browser window. If this sounds strange it’s because it will be working in tandem with another script.

My problem is I don’t want the thumbnail display to be on if there are any subdirectories in the current directory (this keeps navigation cleaner and easier until you get to the treasure at the end of the rainbow). Is there some way to check if there are subdirectories being displayed in the current directory being displayed in the file browser window? Is there even a way to access what directory you are inside of while in the file browser? Or if someone has a better way of accomplishing this goal, by all means let me know, this is just one idea I’m working with to try to accomplish this. Thanks.

For file related work you need to look at the os and os.path modules: https://docs.python.org/3.4/library/os.html

There is “os.listdir” and “os.path.isdir”, for example.

def has_subdirs(path):
return any(True for f in os.listdir(path) if os.path.isdir(os.path.join(path,f)))

Thanks. This helps. I figured as much about needing to import os but wasn’t sure where to start. Appreciate the help.