<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Thomas wrote:<br>
<blockquote cite="midikrfl05b77p2jlbrp3kehvf5o3u8jp35od@4ax.com"
 type="cite">
  <pre wrap="">I'm doing this :

[os.path.join(path, p) for p in os.listdir(path) if \
os.path.isdir(os.path.join(path, p))]

to get a list of folders in a given directory, skipping all plain
files. When used on folders with lots of files,  it takes rather long
time to finish. Just doing  a listdir, filtering out all plain files
and a couple of joins, I didn't think this would take so long. 

Is there a faster way of doing stuff like this?

Best regards,
Thomas
  </pre>
</blockquote>
<br>
I was going to use timeit, but kept encountering a "global name 'os' is
not defined" error.  So, I created my own function named "time_me."  I
created a directory with 5000 files and 3 directories.  I ran your code
on it and got around .34 seconds:<br>
<br>
<font face="Courier New, Courier, monospace">In [38]:
time_me('''[os.path.join(path, p) for p in os.listdir(".") if
os.path.isdir(os.path.join(path, p))]''')<br>
Out[38]: 0.33953285217285156<br>
</font><br>
I tried glob rather than os.listdir.  Not any better:<br>
<br>
<font face="Courier New, Courier, monospace">In [39]: import glob<br>
<br>
In [40]: time_me('''[os.path.join(path, p) for p in glob.glob("*") if
os.path.isdir(os.path.join(path, p))]''')<br>
Out[40]: 0.38322591781616211<br>
</font><br>
I decided, since I was already in the directory, to not do the
os.path.join() on path and p.  Got .23 seconds rather than .34.  That's
probably not an option, though, and it didn't really buy you a whole
lot:<br>
<br>
<font face="Courier New, Courier, monospace">In [42]: time_me('''[p for
p in os.listdir(".") if os.path.isdir(p)]''')<br>
Out[42]: 0.23234295845031738</font><br>
<br>
os.listdir seems to be fairly cheap:<br>
<font face="Courier New, Courier, monospace"><br>
In [43]: time_me("os.listdir('.')")<br>
Out[43]: 0.030396938323974609</font><br>
<br>
I know that none of this is helpful so far, but I don't see how you're
going to get around getting a directory listing and then statting each
file to determine if it's a directory or not.  How you are doing it is
a reasonable solution.  How many files is "lots of files"?  And how
long are you seeing on your system?<br>
<br>
<br>
Jeremy<br>
</body>
</html>