I
I
InternetMaster2021-11-13 11:53:21
Python
InternetMaster, 2021-11-13 11:53:21

How to send a folder to Telegram Bot?

How to send folder to telegram bot? I think you need to use sendDocument for this, but there you can only send files like .txt or .pdf, etc. How do you send a whole folder?
Library - telebot

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
albert-gaynullin, 2021-11-13
@InternetMaster

zipfile library to help.

zfname = f'{Название архива}.zip'  
with ZipFile(zfname, "w") as nz:
    nz.write(f'[путь]/{Название файла1}.[расширение]') 
    nz.write(f'[путь]/{Название файла2}.[расширение]') 
f = open(zfname, 'rb')
bot.send_document([chat_id], f)

M
Maxim Maxim, 2021-11-13
@marklondon

I doubt that you will be able to send the folder itself. You can send the contents of this folder and do something with it. And how to implement it - in a cycle or just drive in one by one each name is already a personal matter for everyone)

S
soremix, 2021-11-13
@SoreMix

Telegram does not have this option. There are two options - either send each file separately, or pack the folder into an archive

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question