0

how to create a multi folders with nested structure in python api in a simple way with out loops like unix command mkdir -p a/b/c/{d,e,f} seems like pathlib or os.mkdirs has no direct provision for this.

tried in this way 'pathlib.Path(dest).mkdir(0o755, parents=True, exist_ok=True') but not working

Ram Ghadiyaram
  • 32,481
  • 14
  • 91
  • 120
  • Is the ```dest``` argument to ```Path()``` actually ```"a/b/c/{d,e,f}"``` ? ```pathlib``` doesn't do brace expansion like shells do. – sj95126 Sep 17 '21 at 02:45
  • exactly is there any smarter way to achieve this like with out writing lot of code? – Ram Ghadiyaram Sep 17 '21 at 03:31
  • You could try ```braceexpand``` as mentioned [in this answer](https://stackoverflow.com/a/38485954/13843268). Other than that, you probably have to craft each path to pass to ```pathlib``` or use something like ```subprocess``` to execute the ```mkdir``` command as you would on the command line. – sj95126 Sep 17 '21 at 03:52

0 Answers0