Java Directory Check checkDirectoryInWorkspace(String directoryName)

Here you can find the source of checkDirectoryInWorkspace(String directoryName)

Description

Check whether there is a directory existing in present workspace, with the given name.

License

Open Source License

Parameter

Parameter Description
directoryName a parameter

Return

true, if directory exists.

Declaration

public static boolean checkDirectoryInWorkspace(String directoryName) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007, 2008 Symbian Software Limited and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://w ww . j a  v a 2  s  .  c o  m
 * Bala Torati (Symbian) - Initial API and implementation
 * IBM Corporation
 *******************************************************************************/

import java.io.File;

import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;

public class Main {
    /**
     * Check whether there is a directory existing in present workspace, with
     * the given name.
     * 
     * @param directoryName
     * @return true, if directory exists.
     * 
     * @since 4.0
     */
    public static boolean checkDirectoryInWorkspace(String directoryName) {

        boolean retVal = false;
        File file = null;

        try {
            file = new File(getWorkspacePath() + directoryName);
        } catch (Exception exp) {

        }
        if ((file != null) && (file.exists()) && (file.isDirectory())) {
            retVal = true;
        }
        return retVal;
    }

    /**
     * This method returns the workspace path present in the workspace
     * 
     * @return String Example : file:/C:/eclipse/workspace/
     * 
     * @since 4.0
     */
    public static IPath getWorkspacePath() {

        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IWorkspaceRoot root = workspace.getRoot();
        IPath workSpacePath = new Path(root.getLocation().toString()
                + File.separator);
        return workSpacePath;

    }
}

Related

  1. checkDirectory(File target)
  2. checkDirectory(final File directory)
  3. checkDirectory(final String dir, final boolean create, final String errorDirName)
  4. checkDirectory(String value)
  5. checkDirectoryArray(String[] names)
  6. checkDirPath(final String path)
  7. checkDirs(File f)
  8. checkDirs(String dir)
  9. checkDirs(String dirName)