Skip to content

Instantly share code, notes, and snippets.

@Stilic
Created August 1, 2021 10:24
Show Gist options
  • Save Stilic/73dc213779a0371a3e78beb270c258bc to your computer and use it in GitHub Desktop.
Save Stilic/73dc213779a0371a3e78beb270c258bc to your computer and use it in GitHub Desktop.
import os
import random
def run(command):
return os.popen(command).read()
def clear():
if os.name == "nt":
os.system("cls")
else:
os.system("clear")
prD = ""
try:
while True:
clear()
if prD == "":
list = run("ls").split("\n")
list.pop(len(list) - 1)
print("Current working directory: " + os.getcwd())
else:
list = run("cd " + prD + " && ls").split("\n")
print("Current working directory: " + prD)
try:
list = [f.name for f in os.scandir(prD) if f.is_dir()]
except NotADirectoryError:
pass
else:
os.chdir(prD)
if len(list) == 0:
print("Content of the directory: empty")
os.chdir(os.path.abspath(".."))
FPrD = os.getcwd()
else:
print("Content of the directory: " + str(list))
r = random.randint(0, len(list))
if r != len(list):
FPrD = os.path.abspath(list[r])
else:
FPrD = os.path.abspath("..")
print()
if input("Continue? ").upper() == "N":
quit()
prD = FPrD
except KeyboardInterrupt:
quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment