48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
import os, sys, telebot
|
|
|
|
# 上传文件
|
|
def upload_file(tb, chat_id, file_dir):
|
|
doc = open(file_dir, 'rb')
|
|
tb.send_document(chat_id, doc)
|
|
|
|
# 上传文件夹内的文件
|
|
def upload_folder(tb, chat_id, folder_dir):
|
|
file_list = sorted(os.listdir(folder_dir))
|
|
for file in file_list:
|
|
path = os.path.join(folder_dir, file)
|
|
if os.path.isfile(path):
|
|
upload_file(tb, chat_id, path)
|
|
else:
|
|
upload_folder(tb, chat_id, path)
|
|
|
|
# 上传
|
|
def upload(tb, chat_id, dir):
|
|
if tb is None:
|
|
log('ERROR: 输入正确的token')
|
|
return
|
|
if chat_id is None:
|
|
log('ERROR: 输入正确的chat_id')
|
|
return
|
|
|