Creating directories

Posted: 7 May 2009 in Branches, Content Store, CSSDK, Directories, Java, Teamsite, Workareas

Here’s a little code to create directories, based on their relative path in the workarea.

    public CSDir findOrCreateDir(String relativePath) {
        CSDir directory = null;
        try {
            directory = (CSDir) getArea().getFile(new CSAreaRelativePath(relativePath));
            if (directory == null) {
                System.out.println("directory " + relativePath + " does not exist.");
                try {
                    System.out.println("creating directory " + relativePath + ".");
                    directory = getArea().getRootDir().createChildDirectory(relativePath);
                } catch (CSException ex) {
                    System.out.print("unable to create directory");
                    Logger.getLogger(MyClass.class.getName()).log(Level.SEVERE, null, ex);
                }
            } else {
                System.out.println("found directory " + relativePath + ".");
            }
        } catch (CSException ex) {
            Logger.getLogger(CreateIntranetSiteAdditionalFilesTask.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            return (directory);
        }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s