def ls(self):
""" Generate a list of InlineKeyboardButton of files and dir in current_dir """
p = Popen('ls', cwd=self.current_dir, shell=True, stdout=PIPE, stderr=PIPE).communicate()
files = str(p[0], 'utf-8').strip().split('\n') # Also contains directories
files = [f for f in files if check_file(f)] # removing bad files...
kb = []
if self.current_dir != '/':
kb.append([InlineKeyboardButton("..", callback_data='..d')])
for f in files: # First the directories...
path = os.path.join(self.current_dir, f)
if os.path.isdir(path):
kb.append([InlineKeyboardButton("dir: {}".format(f),
callback_data="{}d".format(f))])
for f in files: # ...Then the files
path = os.path.join(self.current_dir, f)
if os.path.isfile(path):
kb.append([InlineKeyboardButton("file: {}".format(f),
callback_data="{}f".format(f))])
return kb
评论列表
文章目录