Create directories using macro editor

Everything OAD-related that won't fit in the other categories: share general aspects of macro programming and discuss the OAD environment
Post Reply
user-3185
Posts: 3
Joined: Thu Jan 01, 1970 1:00 am

Create directories using macro editor

Post by user-3185 »

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.
user-6033
Posts: 89
Joined: Thu Jan 01, 1970 1:00 am

Post by user-6033 »

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
user-4
Posts: 397
Joined: Thu Jan 01, 1970 1:00 am

Post by user-4 »

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.
Post Reply