473,473 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

find function

Hi,

is there for python a find() function, like the perl module Find or the
command line tool find?

All I found was os.listdir(<path>), but that does return all files in a
folder. I'd like to have i.e. regex or shell-like file selections, as in:

$ find -name \*.pyc -maxdepth 1

Thanks
Ciao
Uwe
--

Jul 18 '05 #1
1 1790
On Sun, 2004-01-25 at 16:25, Uwe Mayer wrote:
Hi,

is there for python a find() function, like the perl module Find or the
command line tool find?


Try:

import glob
pattern = '*.pyc'
for name in glob.glob(pattern):
print name

glob's not recursive, though. For that, consider os.walk:

import os
path = '.'
extensions = ('.pyc',)
for root, dirs, files in os.walk(path):
for name in files:
prefix, ext = os.path.splitext(name)
if ext not in extensions:
continue
fullname = os.path.join(root, name)
print fullname

The above code may have syntax errors since I didn't run it.

// m
Jul 18 '05 #2

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

Similar topics

4
by: Tom | last post by:
Hi, I need some help with stl maps. I am using a std::map that is sorted in a very special way. Therefore I am using my own sort function. That works fine. But this is only half the problem....
5
by: Tim Eliot | last post by:
Just wondering if anyone has hit the following issue and how you might have sorted it out. I am using the command: DoCmd.TransferText acExportMerge, , stDataSource, stFileName, True after...
5
by: Filips Benoit | last post by:
Dear All, I'm looking for a function that does the same as the find-action in the code-window. Thanks, Filip
5
by: Joerg Battermann | last post by:
Hello there, I have a custom type defined via Public Class Requirement Public IDNumber As Integer Public Name As String Public Description As String Public VersionPlanAttributes As New _
18
by: ma740988 | last post by:
Trying to get more acclimated with the use of function objects. As part of my test, consider: # include <vector> # include <iostream> # include <algorithm> #include <stdexcept> #include...
0
by: kloplop321 | last post by:
I found this code(vb only) and it does about the same thing(in vb, not vb .NET 2005) Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute...
2
by: emily224 | last post by:
Hello, I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer...
9
by: Satish Itty | last post by:
How do I write the following c# code in vb Product FindProduct(string code) { List<Productproducts = getProducts(); return products.Find(delegate(Product bo) { return bo.Code == code; }); }
7
by: Christian Meier | last post by:
Hello Newsgroup I have a question about the find function of std::set. When I have a "std::set<int*>", why can't I call the find() function with an "const int*"? I know that my key type is...
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
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...
1
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
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.