You Are Here:

Community: Developer Discussion Boards

#1 Old Can we search joker files in a list? - 2008-06-27, 22:22

Join Date: Nov 2007
Posts: 34
bakidilek
Offline
Registered User
hi I want to create a code to search joker files in lists but I dont know how can I do it

I created a code


Code:
import appuifw
import e32
import os

def tr(x):return x.decode('utf-8')

imagedir=('C:\\Nokia\\Images\\')
imagedir2='E:\\Images\\'

files=map(tr,os.listdir(imagedir))
files2=map(tr,os.listdir(imagedir2))
files.extend(files2)

index=appuifw.selection_list(files)

print files[index]

in this code I only want to see files endswith .png or .jpg in the selection list?

is there a way to do this?

thanks.
Reply With Quote

#2 Old Re: Can we search joker files in a list? - 2008-06-27, 22:28

Join Date: Mar 2003
Posts: 115
Dansco
Offline
Regular Contributor
Use something like this

Code:
jpg1=files[index].split('.')
jpg2=jpg[1]
if jpg2=="jpg":
   code
elif jpg2=="png":
   more code
Not entirely sure this will work but I've used the split command well before mate
Reply With Quote

#3 Old Re: Can we search joker files in a list? - 2008-06-28, 03:40

Join Date: Jun 2005
Posts: 382
y.a.k
Offline
Regular Contributor
I would use list compherension instead of map():
Code:
files = [x.decode('utf8') for x in os.listdir(imagedir) if os.path.splitext(x)[-1].lower() in ('.jpg', '.png')]
This single line lists the directory, filters the files ending with .jpg or .png, decodes the names to unicode and gives you a list of those names. Python power.

@Dansco

Your code will fail if the filename is "this.is.some.picture.jpg" for example. You would have to use jpg[-1] instead of jpg[1] to get the extension. But it is always a good practice to use the os.path.splitext() function. Why reinventing the wheel?
Reply With Quote

#4 Old Re: Can we search joker files in a list? - 2008-06-28, 09:06

Join Date: Nov 2007
Posts: 34
bakidilek
Offline
Registered User
y.a.k and Dansco thanks a lot I found the answer in y.a.k's code
Reply With Quote

#5 Old Re: Can we search joker files in a list? - 2008-06-28, 18:11

Join Date: Mar 2003
Posts: 115
Dansco
Offline
Regular Contributor
Quote:
Originally Posted by y.a.k View Post
@Dansco

Your code will fail if the filename is "this.is.some.picture.jpg" for example. You would have to use jpg[-1] instead of jpg[1] to get the extension. But it is always a good practice to use the os.path.splitext() function. Why reinventing the wheel?
I just used a bit of code I used
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Pinyin mode for Search box dgaur Symbian User Interface 0 2008-05-06 10:45
Carbide.ui bugs on N73 ME zhvihti Themes/Carbide.ui 8 2007-06-05 09:30
6680 and bluetooth service profiles ceruault Mobile Java Networking & Messaging & Security 1 2005-10-08 23:24
search in a List class pvermeulen Mobile Java General 3 2004-07-13 21:32
Phone List Search & then Phone Call Nokia_Archive Browsing and Mark-ups 1 2002-05-16 02:46

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia