Ejercicio 12c
This commit is contained in:
parent
6d37344f7c
commit
a016ba6c2a
|
@ -11,7 +11,6 @@ parser = argparse.ArgumentParser()
|
|||
parser.add_argument("paths", nargs="+", type=Path)
|
||||
parser.add_argument("-r", "--recursive", action="store_true")
|
||||
args = parser.parse_args()
|
||||
result = ""
|
||||
error = False
|
||||
|
||||
for path in args.paths:
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env python
|
||||
# Exercise 12c
|
||||
# rmdir command
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("paths", nargs="+", type=Path)
|
||||
parser.add_argument("-p", "--parents", action="store_true")
|
||||
args = parser.parse_args()
|
||||
error = False
|
||||
|
||||
for path in args.paths:
|
||||
if path.is_file():
|
||||
print(f"rmdir: fallo al borrar '{path}': No es un directorio")
|
||||
error = True
|
||||
elif len(list(path.glob("*"))) > 0:
|
||||
print(f"rmdir: fallo al borrar '{path}': El directorio no está vacío")
|
||||
error = True
|
||||
else:
|
||||
if args.parents is True:
|
||||
while len(path.parts) > 0:
|
||||
path.rmdir()
|
||||
path = path.parent
|
||||
else:
|
||||
path.rmdir()
|
||||
|
||||
if error:
|
||||
sys.exit(1)
|
Loading…
Reference in New Issue