File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -210,6 +210,7 @@ def open_files(
210
210
num = 1 ,
211
211
protocol = None ,
212
212
newline = None ,
213
+ auto_mkdir = True ,
213
214
expand = True ,
214
215
** kwargs ,
215
216
):
@@ -248,6 +249,9 @@ def open_files(
248
249
newline: bytes or None
249
250
Used for line terminator in text mode. If None, uses system default;
250
251
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)``.
251
255
expand: bool
252
256
**kwargs: dict
253
257
Extra options that make sense to a particular storage connection, e.g.
@@ -284,6 +288,11 @@ def open_files(
284
288
protocol = protocol ,
285
289
expand = expand ,
286
290
)
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 ]
287
296
return OpenFiles (
288
297
[
289
298
OpenFile (
You can’t perform that action at this time.
0 commit comments