View Only
  • 1.  Python... create directory?

    Posted 11-20-2019 13:40

    I need to be able to create a directory, and found this python script

    • ive never used python before, the script thats in the "blank" node.. does it need to stay?  what can i get rid of?
    • Also!! How do i change permission on the folder after I create it? because it becomes locked since I am not an owner lol. I had to have out admin delete the last one.
    import os
    if not os.path.exists('my_folder'):

  • 2.  RE: Python... create directory?

    Posted 11-21-2019 08:05

    Pretty much all of the script should be retained for the node to operate correctly when you are using it to access input data and/or output data at the node's pins.

    You can find additional information on the use of the Python node in the Python Node Getting Started.pdf document which can be found in the 'docs' directory of your LAE install. e.g. C:\Program Files\Lavastorm\LAE6.1\docs

    The os.path.exists() operator does not discriminate between a file and a directory. If you want to check that the target is a directory and it exists then use os.path.isdir() instead.

    The os.chmod() operator can be used to modify the permissions on the directory.

    See the attached example script for some examples. Note, the os.rmdir() operator will only remove an empty directory.


    Attached files



  • 3.  RE: Python... create directory?

    Posted 11-21-2019 08:11

    Note, unlike most other output nodes the Output BRD node can create the directory if it does not already exist.

    See also the Help documentation for the output-related scripting operators that can be used to test for the existence of a file, create, delete, clear and move a file.

  • 4.  RE: Python... create directory?

    Posted 11-21-2019 08:45

    ok, thanks Adrian! I tried and tried and it kept complaining about indents.. i was like what?

    but it really is true! LOL you have to line them up!

    I got it working now!

    so if I change exists to isdir this will work the same? (should not matter really because im only passing in directory)

    if not os.path.exists(PTH+"Clean"):
    if not os.path.exists(PTH+"Fallout"):


    I tried that BRD trick before and it was not very clean (and left a directory I could not delete)


  • 5.  RE: Python... create directory?

    Posted 11-21-2019 09:18

    Yes that should work.


    Python relies on indentation to structure the code blocks within a script. The default script in the node uses tabs. However, when new lines are entered they use multiple space characters for indentation. I find it is simplest to copy the default script into Notepad++ and then use the replace function to change all the tab characters (\t) to be four spaces, and then paste the script back into the node.

  • 6.  RE: Python... create directory?

    Posted 11-21-2019 09:35

    ok cool.


    can python set the graph parameters? I have one called FolderName.. id love to be able to read a directory, then create a sub directory using a date (stripped out of a filename)

    then set the param so it can be used later

  • 7.  RE: Python... create directory?

    Posted 11-21-2019 10:59

    Python can read the graph parameter values but they cannot be written (they are effectively treated as constants when the graph is run).

    You can access the values within the script using textual substitution of the parameter.

    So if you have a graph parameter named 'FolderName' and it has a value set to be '/home/Bob/data' (without the apostrophes) then your script could access the value using the usual textual substitution mechanism, e.g.

    fName = r"{{^FolderName^}}"


    which would result in the 'fName' variable having a value of  "/home/Bob/data"

    Note the presence of the r before the opening quote character - this is useful if you are dealing with a mix of Linux and Windows style paths as the backslash characters in the Windows paths would result in errors. It is best to replace any backslash characters with forward slash characters if possible e.g. using 

    fName = fName.replace("\\", "/")


    Values resulting from textual substitution should be considered as strings - you can then, if required, cast them to an appropriate data type within your script using the relevant Python operator (e.g. float() etc).

    See the Parameters Overview topic in the Help for additional information on textual substitution.

  • 8.  RE: Python... create directory?

    Posted 11-21-2019 11:22

    ahh.. too bad. that couldve been handy.

    thanks for the r" tip though!