[file] Added recursive
option to file.rmdir
.
This commit is contained in:
parent
2c481c54af
commit
a5426ede58
1 changed files with 9 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
|
import shutil
|
||||||
import stat
|
import stat
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from multiprocessing import RLock
|
from multiprocessing import RLock
|
||||||
|
@ -102,13 +103,19 @@ class FilePlugin(Plugin):
|
||||||
)
|
)
|
||||||
|
|
||||||
@action
|
@action
|
||||||
def rmdir(self, directory: str):
|
def rmdir(self, directory: str, recursive: bool = False):
|
||||||
"""
|
"""
|
||||||
Remove a directory. The directory must be empty.
|
Remove a directory. The directory must be empty.
|
||||||
|
|
||||||
:param directory: Directory name/path.
|
:param directory: Directory name/path.
|
||||||
|
:param recursive: If set, the directory and all its contents will be
|
||||||
|
removed recursively (default: False).
|
||||||
"""
|
"""
|
||||||
pathlib.Path(self._get_path(directory)).rmdir()
|
directory = self._get_path(directory)
|
||||||
|
if not recursive:
|
||||||
|
pathlib.Path(directory).rmdir()
|
||||||
|
else:
|
||||||
|
shutil.rmtree(directory)
|
||||||
|
|
||||||
@action
|
@action
|
||||||
def touch(self, file: str, mode=0o644):
|
def touch(self, file: str, mode=0o644):
|
||||||
|
|
Loading…
Reference in a new issue