From 0c6c414cdfc3293449e158c1fc2536dd36aa59a4 Mon Sep 17 00:00:00 2001 From: m5rcel { Marcel } Date: Tue, 9 Sep 2025 17:22:34 +0200 Subject: [PATCH] Update cmd_wdir.py --- commands/cmd_wdir.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/commands/cmd_wdir.py b/commands/cmd_wdir.py index 4ada584..7be8d6b 100644 --- a/commands/cmd_wdir.py +++ b/commands/cmd_wdir.py @@ -1,7 +1,8 @@ import requests from bs4 import BeautifulSoup -from urllib.parse import urljoin, urlparse +from urllib.parse import urljoin from colorama import Fore, Style +import re class WdirCommand: def __init__(self, url): @@ -12,7 +13,7 @@ class WdirCommand: print(Fore.RED + "Usage: wdir " + Style.RESET_ALL) return - # Ensure URL has scheme + # Ensure scheme if not self.url.startswith("http://") and not self.url.startswith("https://"): self.url = "http://" + self.url @@ -37,22 +38,34 @@ class WdirCommand: if href.startswith("?") or href.startswith("#") or href == "../": continue - full_url = urljoin(self.url, href) filename = href.split("/")[-1] + full_url = urljoin(self.url, href) - # Determine file type + # Guess type if "." in filename: ext = filename.split(".")[-1].lower() ftype = f".{ext} file" else: ftype = "Directory" - files.append((filename, ftype, full_url)) + # Try to extract file size and modified date from raw HTML + row_text = link.parent.get_text(" ", strip=True) + size_match = re.search(r"(\d+(?:\.\d+)?\s*(?:KB|MB|GB|B))", row_text, re.I) + date_match = re.search(r"(\d{4}-\d{2}-\d{2} \d{2}:\d{2})", row_text) + + size = size_match.group(1) if size_match else "?" + modified = date_match.group(1) if date_match else "?" + + files.append((filename, ftype, size, modified, full_url)) if not files: print(Fore.YELLOW + "No files or directories found (maybe directory listing is disabled)." + Style.RESET_ALL) return print(Fore.GREEN + "\nFiles found:" + Style.RESET_ALL) - for fname, ftype, furl in files: - print(f" {Fore.CYAN}{fname:<30}{Style.RESET_ALL} {Fore.WHITE}→ {ftype}{Style.RESET_ALL}") + print(Fore.MAGENTA + f"{'Name':<30}{'Type':<15}{'Size':<12}{'Modified':<20}" + Style.RESET_ALL) + print(Fore.MAGENTA + "-" * 77 + Style.RESET_ALL) + + for fname, ftype, size, modified, furl in files: + print(f"{Fore.CYAN}{fname:<30}{Style.RESET_ALL} " + f"{Fore.WHITE}{ftype:<15}{size:<12}{modified:<20}{Style.RESET_ALL}")