Archived:How to search a file extension using PySymbian
Aquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|escreva a sua justificativa}}.
All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.
All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.
Article Metadata
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


Copied from here: File Search
--kiran10182 11:32, 29 June 2008 (EEST)