is file a directory or not, touch if not exist

@param directory
@return true if existing directory or has created new one
493756
protected boolean isDirectory(Resource directory) {
	if (directory.exists()) return directory.isDirectory();
	try {
	    directory.createDirectory(true);
	    return true;
	}
	catch (IOException e) {
	    e.printStackTrace(getErrWriter());
	}
	return false;
    }
375555
function isDirectory(filePath) {
  if (!isExist(filePath)) return false;
  try {
    const stat = fs.statSync(filePath);
    return stat.isDirectory();
  } catch (e) {
    return false;
  }
}
796219
public boolean directoryExists(File[] files) {
        for (int i = 0; i < files.length; i++) {
            if (files[i].isDirectory()) {
                return true;
            }
        }
        return false;
    }
882202
private static String createIfNeeded(String dir) {
        File f = new File(dir);
        if (f.exists()) {
            return dir;
        } else {
            boolean success = f.mkdirs();
            if (success)
                return dir;
            else
                return null;
        }
    }
673178
@Override
	public boolean cd(String directory) {
		boolean flag = true;
		try {
			flag = client.changeWorkingDirectory(directory);
		} catch (IOException e) {
			throw new FtpException(e);
		}
		return flag;
	}
699408
def is_file?(string)
      return false if string.is_a?(StringIO)
      !File.directory?(string) && File.exists?(File.expand_path(string))
    rescue
      false
    end
937526
public ProcBuilder withWorkingDirectory(File directory) {
        if (!directory.isDirectory()) {
            throw new IllegalArgumentException("File '" + directory.getPath() + "' is not a directory.");
        }
        this.directory = directory;
        return this;
    }
607129
public function rm(string $directory): bool {
    if (is_dir($directory)) {
      foreach (new DirectoryIterator(Path::replaceOSSeparator($directory)) as $fileInfo) {
        if (!$fileInfo->isDot()) {
          if ($fileInfo->isDir()) {
            $this->rm($fileInfo->getPathname());
            @rmdir($fileInfo->getPathname());
          } else if ($fileInfo->isFile()) {
            @unlink($fileInfo->getPathname());
          }
        }
      }
      @rmdir($directory);
    }
    return !file_exists($directory);
  }
138119
public static void cleanDirectory(File directory) throws IOException {
    requireNonNull(directory, DIRECTORY_CAN_NOT_BE_NULL);
    if (!directory.exists()) {
      return;
    }

    cleanDirectoryImpl(directory.toPath());
  }
157617
public static File createDir(String dir) {
        // create outdir
        File directory = null;
        if(dir != null) {
            directory = new File(dir);
            if(!(directory.exists() || directory.mkdir())) {
                Utils.croak("Can't find or create directory " + dir);
            }
        }
        return directory;
    }
1089471
private function checkDirectoryBeforeInitialize($directory)
    {
        if (!file_exists($directory)) {
            set_error_handler(function ($errCode, $errStr) use ($directory) {
                $parts = explode(':', $errStr, 2);
                $errorMessage = isset($parts[1]) ? trim($parts[1]) : 'Undefined';

                throw new IOException(sprintf(
                    'Could not create directory "%s". %s',
                    $directory,
                    $errorMessage
                ), $errCode);
            });

            mkdir($directory, 0775);

            restore_error_handler();
        } elseif (!is_dir($directory)) {
            throw new IOException(sprintf(
                'Can not create directory. The path "%s" already exist.',
                $directory
            ));
        } elseif (!is_writable($directory)) {
            throw new IOException(sprintf(
                'The directory "%s" is not writable.',
                $directory
            ));
        }
    }
485310
private void checkDirectory(File d, String dtype) {

        if (!d.isAbsolute()) {
            throw new IllegalArgumentException(dtype
                    + " directory must be an absolute path (" + d.getPath() + ")");
        }
        if (!d.exists()) {
            throw new IllegalArgumentException(dtype
                    + " directory does not exist (" + d.getPath() + ")");
        }
        if (!d.isDirectory()) {
            throw new IllegalArgumentException(dtype
                    + " directory value is not a directory (" + d.getPath() + ")");
        }

    }
30363
public void cleanDirectory( final File directory )
        throws IOException
    {
        if ( !directory.exists() )
        {
            final String message = directory + " does not exist";
            throw new IllegalArgumentException( message );
        }

        if ( !directory.isDirectory() )
        {
            final String message = directory + " is not a directory";
            throw new IllegalArgumentException( message );
        }

        Delete deleteTask = new Delete();
        deleteTask.setProject(getProject());
		deleteTask.setDir(directory);
		deleteTask.execute();
		
		if(!directory.exists()){
			directory.mkdirs();
		}
    }
1150780
@NullSafe
  private File validateDirectory(File directory) {
    return Optional.ofNullable(directory).filter(File::isDirectory)
      .orElseThrow(() -> newIllegalArgumentException("File [%s] is not a valid directory", directory));
  }
1221189
public static void directoryCheck(String dir) throws IOException {
		final File file = new File(dir);

		if (!file.exists()) {
			FileUtils.forceMkdir(file);
		}
	}
298314
def ensure_directory_exists(directory):
  '''
  '''
  if not os.path.exists(directory):
    os.makedirs(directory)
  elif os.path.isfile(directory):
    raise RuntimeError('Path %s is a file, not a directory.' % directory)
659361
public function isExcludedDirectory($directory)
    {
        foreach ($this->getExcludedDirectories() as $pattern) {
            if (Str::is($pattern, $directory)) return true;
        }

        return false;
    }