Skip to content

Commit e3b19cc

Browse files
authored
Revert auto_mkdir default in open() and special case local (#1365)
1 parent 5f79058 commit e3b19cc

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

fsspec/core.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ def open_files(
210210
num=1,
211211
protocol=None,
212212
newline=None,
213+
auto_mkdir=True,
213214
expand=True,
214215
**kwargs,
215216
):
@@ -248,6 +249,9 @@ def open_files(
248249
newline: bytes or None
249250
Used for line terminator in text mode. If None, uses system default;
250251
if blank, uses no translation.
252+
auto_mkdir: bool (True)
253+
If in write mode, this will ensure the target directory exists before
254+
writing, by calling ``fs.mkdirs(exist_ok=True)``.
251255
expand: bool
252256
**kwargs: dict
253257
Extra options that make sense to a particular storage connection, e.g.
@@ -284,6 +288,11 @@ def open_files(
284288
protocol=protocol,
285289
expand=expand,
286290
)
291+
if fs.protocol == "file":
292+
fs.auto_mkdir = auto_mkdir
293+
elif "r" not in mode and auto_mkdir:
294+
parents = {fs._parent(path) for path in paths}
295+
[fs.makedirs(parent, exist_ok=True) for parent in parents]
287296
return OpenFiles(
288297
[
289298
OpenFile(

0 commit comments

Comments
 (0)