Archived:How to search a file extension using PySymbian

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngAquivado: 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.

Article Metadata
Created: gaba88 (26 Jun 2008)
Last edited: hamishwillee (31 May 2013)

The code snippet below in Category:PySymbian shows how to search a file extension.

import os, appuifw
def findfile(folder, file_extension):
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):
elif os.path.isdir(path):
stack.append((path, os.listdir(path)))
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')
for i in path:
print i
This page was last modified on 31 May 2013, at 04:05.
41 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.