Hello,
My question is how to create file directories from inside a Zen macro. I would like to automate an image processing task and automatically create a directory to store the results. Automating the image processing has gone fine, but I'm having trouble figuring out how to create the results directory from inside the macro. Any help is much appreciated.
Create directories using macro editor
Hi,
Try this:
from system.IO import Directory
newdir = r'C:\OAD\temp' #Write full path to your new directory temp
if not Directory.Exists(newdir):
Directory.CreateDirectory(newdir)
Directory contains several useful methods and if you beside importing Directory also imports Path then you can handle most of the file related issues.
Kind regards
Fredrik
Try this:
from system.IO import Directory
newdir = r'C:\OAD\temp' #Write full path to your new directory temp
if not Directory.Exists(newdir):
Directory.CreateDirectory(newdir)
Directory contains several useful methods and if you beside importing Directory also imports Path then you can handle most of the file related issues.
Kind regards
Fredrik
Hello p_piepenhagen,
The answer of Fredrik is, of course, exactly what you asked for.
I just wanted to add that the macro environment is not limited to the ‘ZEN-Functions’ but can be extended by other functionalities e.g. the .Net Framework or IronPython libraries etc.
In the case of Frederik’s answer a part of the .Net Framework has been imported via
from system.IO import Directory
You can also import additional functions e.g. related to file handling via
from system.IO import File
For further information please have a look at the documentation of the .Net Framework in the internet.
Importing IronPython libraries work the same way.
There are also a couple of contributions in this forum.
To get some ideas search for ‘import’ in the OAD forum.
The answer of Fredrik is, of course, exactly what you asked for.
I just wanted to add that the macro environment is not limited to the ‘ZEN-Functions’ but can be extended by other functionalities e.g. the .Net Framework or IronPython libraries etc.
In the case of Frederik’s answer a part of the .Net Framework has been imported via
from system.IO import Directory
You can also import additional functions e.g. related to file handling via
from system.IO import File
For further information please have a look at the documentation of the .Net Framework in the internet.
Importing IronPython libraries work the same way.
There are also a couple of contributions in this forum.
To get some ideas search for ‘import’ in the OAD forum.