473,569 Members | 2,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to search directories under <PATH>

Hi

I have to write a function that returns a list of all directories under
<PATH> (should work on linux and windows). it should be easy to write a
loop that goes through every directory... and so on, but I was wondering
if there's faster/more economic way, something like 'find <PATH> -type d'.
I couldn't find any 'find' module for python.

any ideas?

thanx
--
Haim

Jul 18 '05 #1
3 1663
Haim,

google for python path module

cheers Harald
Jul 18 '05 #2
os.path.exists( ) is what you want.

Secondly, If you want to traverse path
hierarchy use os.path.walk().

HTH,
Larry Bates
Syscon, Inc.

"Haim Ashkenazi" <ha**@babysnake s.org> wrote in message
news:ma******** *************** *************** @python.org...
Hi

I have to write a function that returns a list of all directories under
<PATH> (should work on linux and windows). it should be easy to write a
loop that goes through every directory... and so on, but I was wondering
if there's faster/more economic way, something like 'find <PATH> -type d'.
I couldn't find any 'find' module for python.

any ideas?

thanx
--
Haim

Jul 18 '05 #3
On Sat, 26 Jun 2004 08:21:25 -0500, Larry Bates wrote:
os.path.exists( ) is what you want.

Secondly, If you want to traverse path
hierarchy use os.path.walk().

it shows I'm a newbie... :)

I already found out that os.walk do exactly what I want:

for root, dirs, files in walk(<PATH>):
for dir in dirs:
list.append(roo t + dir)

this will generate a list of directories under <PATH>

thanx
--
Haim

Jul 18 '05 #4

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

Similar topics

4
16704
by: Carsten Kraft | last post by:
Hello Newsgroup, I am searching for function which returns me filename from a string that has the file + filepath. ( string sFile = "C:\DIR\SUBDIR\TEST.XML" => TEST.XML) Is there a functional class for this or what have I to do? Thanks alot ...
2
2996
by: Susan Baker | last post by:
Hi, I am (trying) to compile some code I downloaded from the internet. The sources contain references to header files - using the form : #include <pathname/file> If I change the form to this: #include "pathname/file"
7
6370
by: TLM | last post by:
I am trying to build a web application that will contain links to files on a users local computer. I am assuming that the files will be in a known location and can display in a browser window. I have my ASP.NET application building links along the lines of file://c:/<path to file>
0
2857
by: Andrzej Lipski | last post by:
Hello I am developing a Windows Ce 5.0 mobile application. I followed the example shown at : Creating Self-Updating Applications With the .NET Compact Framework http://msdn2.microsoft.com/en-us/library/aa446487.aspx I was able to build the Cab file installer and Setup for the application just fine and I created the CustomInstaller in VB...
10
4428
by: Andrew Backer | last post by:
I have a few file:///c:/windows/somewhere style uris that I need to convert to the actual physical path. I am hoping there is a built in way to handle this. I know I can do some text replacing and get the path, at least in this case, but I'd rather not do that if there is something that already does it more robustly. // Andrew
1
2804
by: dryajov | last post by:
Hi I'm not sure if this should go here in the first place, this is more likely an ODBC driver issue. I'm having the strangest behavior when trying to do an insert into an access database from a C++ application, thru ODBC. I'm able to successfully open a connection to the DB and perform selects, but when I try to do an insert the strangest thing...
3
18619
by: Shinis | last post by:
I developed a site using asp.net with vb script.In local machine its working fine.. But when deployed it shows the following error its my code filepath = Server.MapPath("http://www.mintmenadev.com/z/test/cms/Movies/" + FileUpload1.FileName) FileUpload1.SaveAs(Server.MapPath(filepath)) it shows following error
5
4052
by: Kyle Hayes | last post by:
Is there a way to use the 'r' in front of a variable instead of directly in front of a string? Or do I need to use a function to get all of the slashes automatically fixed? /thanks -Kyle
0
7698
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7673
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7970
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.