async def ls_dir(message: Message) -> None: """ list dir """ path = Config.DOWN_PATH if '-d' in message.flags else message.input_str or '.' if not exists(path): await message.err("path not exists!") return path_ = Path(path) out = f"<b>PATH</b> : <code>{path}</code>\n\n" if path_.is_dir(): folders = '' files = '' for p_s in sorted(path_.iterdir(), key=lambda a: sort_file_name_key(a.name)): if p_s.is_file(): if str(p_s).endswith((".mp3", ".flac", ".wav", ".m4a")): files += '🎵' elif str(p_s).endswith( (".mkv", ".mp4", ".webm", ".avi", ".mov", ".flv")): files += '📹' elif str(p_s).endswith((".zip", ".tar", ".tar.gz", ".rar")): files += '🗜' elif str(p_s).endswith((".jpg", ".jpeg", ".png", ".gif", ".bmp", ".ico", ".webp")): files += '🖼' else: files += '📄' size = os.stat(str(p_s)).st_size files += f" <code>{p_s.name}</code> <i>({humanbytes(size)})</i>\n" else: folders += f"📁 <code>{p_s.name}</code>\n" out += (folders + files) or "<code>empty path!</code>" else: size = os.stat(str(path_)).st_size out += f"📄 <code>{path_.name}</code> <i>({humanbytes(size)})</i>\n" await message.edit_or_send_as_file(out, parse_mode='html')
def explorer(_path: Path) -> None: if _path.is_file() and _path.stat().st_size: file_paths.append(_path) elif _path.is_dir(): for i in sorted(_path.iterdir(), key=lambda a: sort_file_name_key(a.name)): explorer(i)