[Zope] How to check for a folder's existence and create it if it doesn'texist?

Randall F. Kern randy@spoke.net
Wed, 28 Feb 2001 12:11:00 -0800


try something like this, assuming the id of the folder you want is
'myFolder':

<dtml-if expr=3D"'myFolder' not in objectIds('Folder')">
  <dtml-call expr=3D"manage_addFolder('myFolder', 'title of my new
folder')">
</dtml-if>

The problem with using <dtml-in> is it will try to add the new folder
once for every folder in the parent folder, and will fail to create the
folder if the parent folder is empty.

-Randy

> -----Original Message-----
> From: Paul Zwarts [mailto:paul.zwarts@oratrix.com]
> Sent: Wednesday, February 28, 2001 8:55 AM
> To: Chris Muldrow
> Cc: zope@zope.org
> Subject: Re: [Zope] How to check for a folder's existence and=20
> create it
> if it doesn'texist?
>=20
>=20
> Hi!
>=20
> Perhaps something like this:
>=20
> <dtml-in expr=3D"objectValues('Folder')">
>    <dtml-if id=3D=3D2001>
>        Matches
>    <dtml-else>
>        <dtml-call=20
> "nameofFolder.manage_addFolder('titleofFolder', 'something
> else?')">
>    </dtml-if>
> </dtml-in>
>=20
> You'll have to check if that actually works, because somehow=20
> it seems wrong...
> but anyhow, It should be enough to go on....
>=20
> Im pretty much a newbie, but I had alot of help from the list=20
> today, so I try
> to return the favour : )
> Cheers,
> Paz
>=20
>=20
> Chris Muldrow wrote:
>=20
> > I'm trying create a method to go through a site and create=20
> certain folders
> > if they don't already exist. I can check for the existence=20
> of the folders
> > with this:
> >
> > <dtml-in expr=3D"objectValues('Folder')">
> > <dtml-if "id=3D=3D'2001'">
> > It matches<p>
> > </dtml-if>
> >
> > </dtml-in>
> >
> > But how do I craft the "else" to create the folder?=20
> Obviously, if I throw
> > the <dtml-else> inside the "in" loop, it'll throw itself=20
> into the "else"
> > action for every iteration where it doesn't find the named folder.
> >
> > -- Chris Muldrow, muldrow@mac.com
> >
> > _______________________________________________
> > Zope maillist  -  Zope@zope.org
> > http://lists.zope.org/mailman/listinfo/zope
> > **   No cross posts or HTML encoding!  **
> > (Related lists -
> >  http://lists.zope.org/mailman/listinfo/zope-announce
> >  http://lists.zope.org/mailman/listinfo/zope-dev )
>=20
>=20
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -=20
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>=20