From 97acf39d5a689ad6a6bb1da8b7627f6406d7c570 Mon Sep 17 00:00:00 2001 From: yanghua Date: Mon, 19 Aug 2024 20:03:53 +0800 Subject: [PATCH] [TOSFS #10] Implement rmdir API --- tosfs/core.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tosfs/core.py b/tosfs/core.py index d63a3af..4f9e474 100644 --- a/tosfs/core.py +++ b/tosfs/core.py @@ -204,7 +204,29 @@ def info( return self._try_dir_info(bucket, key, path, fullpath) def rmdir(self, path: str) -> None: - """Remove a directory, if empty.""" + """ + Remove a directory if it is empty. + + Parameters + ---------- + path : str + The path of the directory to remove. The path should be in the format + `tos://bucket_name/directory_path`. + + Raises + ------ + FileNotFoundError + If the directory does not exist. + NotADirectoryError + If the path is not a directory. + TosfsError + If the directory is not empty or if there is an error during the removal process. + + Examples + -------- + >>> fs = TosFileSystem() + >>> fs.rmdir("tos://mybucket/mydir/") + """ path = self._strip_protocol(path).rstrip("/") + "/" bucket, key, _ = self._split_path(path) if not key: