mirror of
https://github.com/m4rcel-lol/m5rcode.git
synced 2025-12-06 19:13:57 +05:30
Create cmd_dir.py
This commit is contained in:
committed by
GitHub
parent
9bc62fb9bc
commit
7ef4a4f20f
29
commands/cmd_dir.py
Normal file
29
commands/cmd_dir.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import os
|
||||||
|
from colorama import Fore
|
||||||
|
|
||||||
|
class DirCommand:
|
||||||
|
def __init__(self, cwd, target):
|
||||||
|
self.cwd = cwd
|
||||||
|
self.target = target if target else cwd
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
path = os.path.abspath(os.path.join(self.cwd, self.target))
|
||||||
|
|
||||||
|
if not os.path.exists(path):
|
||||||
|
print(Fore.RED + f"No such file or directory: {self.target}")
|
||||||
|
return
|
||||||
|
|
||||||
|
if os.path.isfile(path):
|
||||||
|
print(Fore.GREEN + f"{self.target} (file)")
|
||||||
|
return
|
||||||
|
|
||||||
|
print(Fore.CYAN + f"Directory listing for {path}:\n")
|
||||||
|
try:
|
||||||
|
for item in os.listdir(path):
|
||||||
|
full_path = os.path.join(path, item)
|
||||||
|
if os.path.isdir(full_path):
|
||||||
|
print(Fore.BLUE + f"[DIR] {item}")
|
||||||
|
else:
|
||||||
|
print(Fore.GREEN + f"[FILE] {item}")
|
||||||
|
except PermissionError:
|
||||||
|
print(Fore.RED + "Access denied.")
|
||||||
Reference in New Issue
Block a user