I search for similar file names & want to upload them for user.
My problem is that when I want to use Try/Except to see this files exists, If files exists, Try & Else Blocks works correctly But If file doesn't exists, It doesn't show user the text ... What is the problem ?
search = str(args[0])
pattern = re.compile('.*%s.*\.pdf' %search, re.I)
for files in filter(pattern.search, os.listdir('.')):
try:
requested_file = open(files, 'rb')
except IOError:
bot.sendChatAction(chat_id, 'typing')
bot.sendMessage(chat_id, "This File Doesn't Exists")
else:
bot.sendChatAction(chat_id, 'typing')
bot.sendMessage(chat_id, "The File You Needed : " + files)
bot.sendChatAction(chat_id, 'upload_document')
bot.sendDocument(chat_id, requested_file, files)
requested_file.close()