Set the directory and test that the directory exists and is contained within the Configuration
directory.

@param directory the new directory
972495
public void setDirectory(final String directory) {
        this.directory = new File(this.configuration.getDirectory(), directory);
        if (!this.directory.exists()) {
            throw new IllegalArgumentException(String.format(
                    "Directory does not exist: %s.\n" +
                            "Configuration contained value %s which is supposed to be relative to " +
                            "configuration directory.",
                    this.directory, directory));
        }

        if (!this.directory.getAbsolutePath()
                .startsWith(this.configuration.getDirectory().getAbsolutePath())) {
            throw new IllegalArgumentException(String.format(
                    "All files and directories must be contained in the configuration directory the " +
                            "directory provided in the configuration breaks that contract: %s in config " +
                            "file resolved to %s.",
                    directory, this.directory));
        }
    }
673178
@Override
	public boolean cd(String directory) {
		boolean flag = true;
		try {
			flag = client.changeWorkingDirectory(directory);
		} catch (IOException e) {
			throw new FtpException(e);
		}
		return flag;
	}
17130
def set_cache_dir(directory):
    
    global cache_dir

    if directory is None:
        cache_dir = None
        return

    if not os.path.exists(directory):
        os.makedirs(directory)
    if not os.path.isdir(directory):
        raise ValueError("not a directory")
    cache_dir = directory
236950
public void setCodeDirectory(String codeDirectory) {
        this.codeDirectory = codeDirectory;
        if (compiler instanceof AbstractCompiler) {
            ((AbstractCompiler) compiler).setCodeDirectory(codeDirectory);
        }
    }
79873
public static boolean createOrCleanDirectory(String directory) {
    // if the directory does not exist, create it.
    if (!FileUtils.isDirectoryExists(directory)) {
      LOG.fine("The directory does not exist; creating it.");
      if (!FileUtils.createDirectory(directory)) {
        LOG.severe("Failed to create directory: " + directory);
        return false;
      }
    }

    // Cleanup the directory
    if (!FileUtils.cleanDir(directory)) {
      LOG.severe("Failed to clean directory: " + directory);
      return false;
    }

    return true;
  }
479491
private void processDirectory(File directory) throws IOException, ClassNotFoundException {

        findFiles(directory);
        File[] files = directory.listFiles();
        if (files != null) {
            for (File file : files) {
                if (file.isDirectory()) {
                    processDirectory(file);
                }
            }
        }
    }
363982
public static void createDirectories(final String directory) {
        if (directory == null) return;
        final File f = new File(directory);
        if (!f.isDirectory()) {
            if (!f.mkdirs()) throw new RuntimeException("couldn't create "
                    + directory);
        }
    }
333982
public static function SetDirectory($dir) {
    if (!is_dir($dir)) {
      if (!@\mkdir($dir, 0700, TRUE)) {
        throw new \InvalidArgumentException("dir $dir does not exist and could not be created");
      }
    }

    self::$DIR = realpath($dir);
  }
145839
public static void recursivelyDeleteDirectory(File directory) throws IOException {
    if (!directory.exists()) {
      return;
    }
    checkArgument(directory.isDirectory(), "Cannot recursively delete a non-directory");
    walkFileTree(directory.toPath(), new DeletionFileVisitor());
  }
876140
public static void mkdirs(File directory) throws CreateDirectoryException {
    if (directory.exists()) {
      // file exists and *is* a directory
      if (directory.isDirectory()) {
        return;
      }

      // file exists, but is not a directory - delete it
      if (!directory.delete()) {
        throw new CreateDirectoryException(
            directory.getAbsolutePath(),
            new FileDeleteException(directory.getAbsolutePath()));
      }
    }

    // doesn't exist. Create one
    if (!directory.mkdirs() && !directory.isDirectory()) {
      throw new CreateDirectoryException(directory.getAbsolutePath());
    }
  }
204907
public void setSrcdir(Path srcDir) {
        if (src == null) {
            src = srcDir;
        } else {
            src.append(srcDir);
        }
    }
578233
public void setWorkingDirectory(File dir) {
        if (!dir.exists()) {
            throw new IllegalArgumentException(dir + " doesn't exist.");
        }
        pb.directory(dir);
    }
1071281
@Reqiured
    public void setDumpDirectory(String dumpDirectory) {
        if (dumpDirectory != null && dumpDirectory.trim().length() > 0) {
            File file = new File(dumpDirectory);
            if (file.exists() || file.mkdirs()) {
                this.dumpDirectory = file;
            }
        }
    }
1048942
protected function checkDirectory(string $directory, bool $create = false)
    {
        if (!file_exists($directory) &&
            ($create === false || (!@mkdir($directory, 0777, true) && !is_dir($directory)))
        ) {
            throw new ParserConfigurationException(
                "Directory '$directory' does not exist and could not be created.",
                1458974127
            );
        }
    }
1128488
public void setDir(String dir)
    {
        _spanState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.DIR, dir);
    }
841753
protected function ensureDirectoryExists($dir)
    {
        if (! file_exists($dir) && ! @mkdir($dir, 0777, true) && ! is_dir($dir)) {
            throw new InvalidConfigurationException(sprintf('Directory "%s" cannot be created!', $dir), 1451862775);
        }
    }
659456
static File validateDirectory(final File directory) {

        File newDirectory = null;

        try {
            newDirectory = AccessController.doPrivileged(new java.security.PrivilegedExceptionAction<File>() {
                @Override
                public File run() throws Exception {
                    boolean ok = true;

                    if (!directory.exists())
                        ok = directory.mkdirs() || directory.exists(); //2nd exists check is necessary to close timing window

                    if (!ok) {
                        Tr.error(tc, "UNABLE_TO_DELETE_RESOURCE_NOEX", new Object[] { directory.getAbsolutePath() });
                        return null;
                    }
                    return directory;
                }
            });
        } catch (PrivilegedActionException e) {
            Tr.error(tc, "UNABLE_TO_DELETE_RESOURCE", new Object[] { directory.getAbsolutePath(), e });
        }

        return newDirectory;
    }