Categories: Python | S60 | Code Examples | How To | Files/Data
This page was last modified 22:35, 7 July 2008.
How to search a file extension
From Forum Nokia Wiki
The code snippet below in PyS60 shows how to search a file extension.
import os, appuifw def findfile(folder, file_extension): p=[] stack = [(folder, os.listdir(folder))] while stack: folder, names = stack[-1] while names: name = names.pop() path = os.path.join(folder, name) if os.path.isfile(path): if name.lower().endswith(file_extension): p.append(path) elif os.path.isdir(path): stack.append((path, os.listdir(path))) break else: stack.pop() return p # Ask for the extension of the file to search for file_extension = appuifw.query(u'Enter file extension', 'text') # Specify the folder to look in; file extension is used in lower case for # case insensitive comparison path = findfile('C:\\', file_extension.lower()) # Display the path or error message if not found if path is None: appuifw.note(u'Not found') else: for i in path: print i
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Carbide C++ : ..... .pkg does not exist. Skipping... | satishkatta | Carbide.c++ and CodeWarrior Tools | 144 | 2008-08-07 11:16 |
| Sending video (.3gp) to P800 | heemeng | General Messaging | 0 | 2003-07-11 06:24 |
| Deploying JAR/JAD file with IIS ? | vandoni | Mobile Java General | 7 | 2003-06-06 21:15 |
| call forward to an numer with extension | etsang3 | Bluetooth Technology | 2 | 2007-06-20 21:18 |
| Dynamic xhtml page via php | adeoduye@hotmail.com | General Browsing | 9 | 2007-03-26 10:12 |
