I'm trying to make a bash adaptation (the Linux terminal) in Windows, for this I'm using Python.
#-*- coding: utf-8 -*-
import subprocess
import os
if __name__ == '__main__':
wt = True
while wt:
cmd = str(raw_input("{}>".format(os.getcwd())))
if cmd == "help":
print('''de momento no pondré este comando porque el output es largo''')
elif cmd == "clear":
subprocess.call(["cmd.exe","/c","cls"])
elif cmd [:2] == "ls" and cmd[2:] == "":
dirlist = os.listdir('.')
for file in dirlist:
print(file)
elif cmd[:6] == "mkdir ":
try:
os.mkdir(cmd[6:])
except Exception as e:
print("ese directorio ya existe")
elif cmd[:3] == "cd ":
try:
os.chdir(cmd[3:])
except Exception as e:
print("el sistema no puede encontrar la ruta")
elif cmd[:3] == "rm":
pass
The problem is in the rm
command, I just do not know how to do it.
I thought about putting subprocess.call(["cmd.exe","/c","del (archivo)"])
but it was going to complicate me anyway, because in batch (cmd) files and directories are deleted with different commands, then I would have to make the program identify if it is a directory or a file.
How can I delete files with python?
O
How can I make Python distinguish if something is a file or a directory?
Any of the 2 answers will be useful, thanks