Namespaces
Variants
Actions
Revision as of 05:22, 27 July 2012 by hamishwillee (Talk | contribs)

Archived:How to search a file extension using PySymbian

Jump to: navigation, search
Article Metadata

Article
Created: gaba88 (26 Jun 2008)
Last edited: hamishwillee (27 Jul 2012)

The code snippet below in Category:PySymbian 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
139 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved