473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Directory


I would like to get a list of sub directories in a directory.
If I use os.listdir i get a list of directories and files in that .
i only want the list of directories in a directory and not the files
in it.
anyone has an idea regarding this.

Jul 30 '07 #1
4 1088
Rohan wrote:
I would like to get a list of sub directories in a directory.
If I use os.listdir i get a list of directories and files in that .
i only want the list of directories in a directory and not the files
in it.
anyone has an idea regarding this.
Look up os.walk (allows you to selectively walk over files and directories)
and/or os.path.isdir (allows you to test if a given path is a directory)

--irmen
Jul 30 '07 #2
On 30 Lip, 23:43, Rohan <vodela....@gmail.comwrote:
I would like to get a list of sub directories in a directory.
If I use os.listdir i get a list of directories and files in that .
i only want the list of directories in a directory and not the files
in it.
anyone has an idea regarding this.
Hi Rohan,

http://diveintopython.org/file_handling/os_module.html

Hope this helps,

Cheers,
Marek

Jul 31 '07 #3
Rohan wrote:
I would like to get a list of sub directories in a directory.
If I use os.listdir i get a list of directories and files in that .
i only want the list of directories in a directory and not the files
in it.
anyone has an idea regarding this.
How far down do you want to go?

All the way to the bottom:

for root, dirs, files in os.walk('.'):
for d in dirs:
print os.path.join(root, d)

####################################

Only your current directory:

x = os.listdir('.')
for item in x:
if os.path.isdir(item):
print item
Jul 31 '07 #4
Rohan wrote:
I would like to get a list of sub directories in a directory.
If I use os.listdir i get a list of directories and files in that .
i only want the list of directories in a directory and not the files
in it.
anyone has an idea regarding this.
import os
listofdirs=[d for d in os.listdir(mydir) if os.pathisdir(d)]

-Larry
Aug 2 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ed | last post by:
Hello All, I posted earlier about a problem I was having with editing or pasting/deleting files in the "Home Directory" of my web server. I just noticed that the "Home Directory" option in the...
2
by: Dave Johnston | last post by:
Hi, I'm currently trying to create a wrapper that uses C functions but behaves like ifstream (from fstream.h) - this is because the platform I'm using (WinCE) doesn't support streams and this is...
8
by: James Owens | last post by:
I'm a relative newbie, interested in storing the information from several server directories and subdirectories in XML so that I can present it selectively using XSL (all files updated today or...
4
by: Elmo Watson | last post by:
Is there a way, with the System.IO class, to do a recursive list of a directory structure? For instance, in DirectoryInfo, you have GetDirectories and GetFiles .... In Directory, you have...
5
by: Bas Hendriks | last post by:
Has anyone any idea how asp.net find it's files back after compiling them to the temporary asp.net directory? I found on numerous webpages that the directorynames are chosen random but cannot find...
6
by: dave | last post by:
I really have 2 questions regarding the following xml snippet. The xml is a directory representation. <?xml version="1.0" standalone="yes"?> <FileSystem> <Row> <ID>1</ID> <Name>Root</Name>...
8
by: theWizard1 | last post by:
Using Asp.NET 1.1, and C#. I have a directory for the website, and a directory under it named Secure. I have a web.config in each of the above directories. The web.config in the Secure...
28
by: Peter Oliphant | last post by:
I have written a program using MS VS VC++ 2005 Express, /cli pure. Upon compiling it it works fine in the GUI development environment. It also works fine as a Debug stand-alone. ut I had an odd...
65
by: Hongyu | last post by:
Dear all: I am trying to write to a file with full directory name and file name specified (./outdir/mytestout.txt where . is the current directory) in C programming language and under Unix, but...
6
by: falconsx23 | last post by:
I am trying to write a code for a Phone Directory program. This program is suppose to allow the user to enter a name or directory and then program can either add, save or even delete an entry. Also...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.