Skip to content

Commit 0c469bf

Browse files
authored
Merge pull request #678 from d-v-b/sequential_rm
LocalFileSystem.rm support for a sequence of string arguments
2 parents c3dac4f + 700ed8a commit 0c469bf

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

fsspec/implementations/local.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,18 @@ def mv_file(self, path1, path2, **kwargs):
122122
shutil.move(path1, path2)
123123

124124
def rm(self, path, recursive=False, maxdepth=None):
125-
path = self._strip_protocol(path).rstrip("/")
126-
if recursive and self.isdir(path):
125+
if isinstance(path, str):
126+
path = [path]
127127

128-
if os.path.abspath(path) == os.getcwd():
129-
raise ValueError("Cannot delete current working directory")
130-
shutil.rmtree(path)
131-
else:
132-
os.remove(path)
128+
for p in path:
129+
p = self._strip_protocol(p).rstrip("/")
130+
if recursive and self.isdir(p):
131+
132+
if os.path.abspath(p) == os.getcwd():
133+
raise ValueError("Cannot delete current working directory")
134+
shutil.rmtree(p)
135+
else:
136+
os.remove(p)
133137

134138
def _open(self, path, mode="rb", block_size=None, **kwargs):
135139
path = self._strip_protocol(path)
@@ -177,7 +181,7 @@ def _isfilestore(self):
177181

178182

179183
def make_path_posix(path, sep=os.sep):
180-
""" Make path generic """
184+
"""Make path generic"""
181185
if isinstance(path, (list, set, tuple)):
182186
return type(path)(make_path_posix(p) for p in path)
183187
if "~" in path:

fsspec/implementations/tests/test_local.py

+5
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,11 @@ def test_file_ops(tmpdir):
399399
fs.rm(tmpdir + "/afile3", recursive=True)
400400
assert not fs.exists(tmpdir + "/afile3")
401401

402+
files = [tmpdir + "/afile4", tmpdir + "/afile5"]
403+
[fs.touch(f) for f in files]
404+
fs.rm(files)
405+
assert all(not fs.exists(f) for f in files)
406+
402407
fs.rm(tmpdir, recursive=True)
403408
assert not fs.exists(tmpdir)
404409

0 commit comments

Comments
 (0)