Creating directories within python script, os.mkdir causing issues

kman88
Level 2
Creating directories within python script, os.mkdir causing issues

Hello, I want to do something very simpple. I would like to create directories within my output or input folders that currently do not exist. Normally this would easily be achievable through the python command os.mkdir. Here is my code:

import dataiku
import pandas as pd, numpy as np
from dataiku import pandasutils as pdu
import os

# Read recipe inputs
test = dataiku.Folder("SZxomfdY")
test_info = test.get_info()

# Write recipe outputs
outputfolder = dataiku.Folder("DBryoOH2")
outputfolder_info = outputfolder.get_info()

#for file in test.list_paths_in_partition():
    #print(file)
    
outputdir = outputfolder_info['accessInfo']['root']
newoutput = os.path.join(outputdir,'newdir')
print(newoutput)
os.mkdir(newoutput)

however I get the error 

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-29-3b604d987ec9> in <module>()
     19 newoutput = os.path.join(outputdir,'newdir')
     20 print(newoutput)
---> 21 os.mkdir(newoutput)

 I don't understand though, it can't locate the folder however it shouldn't be locating the folder, it should be making the folder. Does anyone have any idea what's going on?

0 Kudos
2 Replies
Ignacio_Toledo

Hi @kman88,

The FileNotFoundError also happens when you want to create a new folder within a folder that doesn't exist in the first place. However, your python code should work (I did test  it just in case, and it was successful).

Could you share the output from

print(newoutput)

?

If that doesn't give some idea of what might be happening, the next steps would be to check what kind of managed folder are you using. Is it a local filesystem managed folder?

0 Kudos
Marine
Dataiker

Hi @kman88,  

To create directories in DSS, I'd recommend using the Dataiku's API instead of mkdir, it is more convenient to manage permissions and handle the user isolation framework. 

Could this thread solve your issue ?