Ejercicio 12b
This commit is contained in:
parent
675fd8ad69
commit
6d37344f7c
|
@ -1,12 +1,27 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# Exercise 12a
|
# Exercise 12b
|
||||||
# ls command
|
# rm command
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import shutil
|
||||||
import argparse
|
import argparse
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("paths", default=Path().cwd(), nargs="*", type=Path)
|
parser.add_argument("paths", nargs="+", type=Path)
|
||||||
parser.add_argument("-r", "--recursive", action="store_true")
|
parser.add_argument("-r", "--recursive", action="store_true")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
result = ""
|
result = ""
|
||||||
|
error = False
|
||||||
|
|
||||||
|
for path in args.paths:
|
||||||
|
if path.is_dir() and args.recursive is False:
|
||||||
|
print(f"rm: no se puede borrar '{path}': Es un directorio")
|
||||||
|
error = True
|
||||||
|
elif path.is_file():
|
||||||
|
path.unlink()
|
||||||
|
else:
|
||||||
|
shutil.rmtree(path)
|
||||||
|
|
||||||
|
if error:
|
||||||
|
sys.exit(1)
|
||||||
|
|
Loading…
Reference in New Issue