Namespaces
Variants
Actions

Archived:Como pesquisar uma extensão de arquivo

Jump to: navigation, search
Archived.png
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.
Dados do artigo

Compatibilidade
Plataforma(s): Python for Symbian

Artigo
Tradução:
Por _katy_
Última alteração feita por hamishwillee em 07 May 2013

O código abaixo, em Pys60, mostra como procurar uma extensão de um arquivo.


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
 
# Pergunta qual o tipo de extensão de arquivo a ser procurada
file_extension = appuifw.query(u'Enter file extension', 'text')
 
# Especifica a pasta onde deve ser feita a pesquisa; a extensão do arquivo é usada em
# "caixa baixa" (lower case) para comparação independente do formato (case insensitive)
path = findfile('C:\\', file_extension.lower())
 
# Exibe o canhinho ou uma mensagem de erro caso não seja encontrado
if path is None:
appuifw.note(u'Not found')
else:
for i in path:
print i
This page was last modified on 7 May 2013, at 13:40.
259 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