Tabnine Logo
File.isDirectory
Code IndexAdd Tabnine to your IDE (free)

How to use
isDirectory
method
in
java.io.File

Best Java code snippets using java.io.File.isDirectory (Showing top 20 results out of 77,103)

Refine searchRefine arrow

  • File.<init>
  • File.exists
  • File.listFiles
  • File.getName
  • File.getAbsolutePath
canonical example by Tabnine

public long getDirectorySize(File file) {
 if (!file.exists()) {
  return 0;
 }
 if (file.isFile()) {
  return file.length();
 }
 File[] files;
 if (!file.isDirectory() || (files = file.listFiles()) == null) {
  return 0;
 }
 return Arrays.stream(files).mapToLong(f -> getDirectorySize(f)).sum();
}
origin: stackoverflow.com

 File f = new File(filePathString);
if(f.exists() && !f.isDirectory()) { 
  // do something
}
origin: libgdx/libgdx

  @Override
  public boolean accept (File f, String s) {
    return (new File(f, s).isDirectory());
  }
}
origin: androidannotations/androidannotations

  @Override
  public boolean accept(File f) {
    return f.exists() && f.isDirectory();
  }
};
origin: stackoverflow.com

 File folder = new File("your/path");
File[] listOfFiles = folder.listFiles();

  for (int i = 0; i < listOfFiles.length; i++) {
   if (listOfFiles[i].isFile()) {
    System.out.println("File " + listOfFiles[i].getName());
   } else if (listOfFiles[i].isDirectory()) {
    System.out.println("Directory " + listOfFiles[i].getName());
   }
  }
origin: libgdx/libgdx

static private boolean deleteDirectory (File file) {
  if (file.exists()) {
    File[] files = file.listFiles();
    if (files != null) {
      for (int i = 0, n = files.length; i < n; i++) {
        if (files[i].isDirectory())
          deleteDirectory(files[i]);
        else
          files[i].delete();
      }
    }
  }
  return file.delete();
}
origin: org.testng/testng

private void addOutputDir(List<String> argv) {
 if (null != m_outputDir) {
  if (!m_outputDir.exists()) {
   m_outputDir.mkdirs();
  }
  if (m_outputDir.isDirectory()) {
   argv.add(CommandLineArgs.OUTPUT_DIRECTORY);
   argv.add(m_outputDir.getAbsolutePath());
  } else {
   throw new BuildException("Output directory is not a directory: " + m_outputDir);
  }
 }
}
origin: apache/flink

  @VisibleForTesting
  static File generateStagingTempFilePath(File targetFile) {
    checkArgument(targetFile.isAbsolute(), "targetFile must be absolute");
    checkArgument(!targetFile.isDirectory(), "targetFile must not be a directory");

    final File parent = targetFile.getParentFile();
    final String name = targetFile.getName();

    checkArgument(parent != null, "targetFile must not be the root directory");

    while (true) {
      File candidate = new File(parent, "." + name + ".inprogress." + UUID.randomUUID().toString());
      if (!candidate.exists()) {
        return candidate;
      }
    }
  }
}
origin: apache/storm

private static void validateCreateOutputDir(File dir) {
  if (!dir.exists()) {
    dir.mkdirs();
  }
  if (!dir.canWrite()) {
    throw new IllegalStateException(dir.getName() + " does not have write permissions.");
  }
  if (!dir.isDirectory()) {
    throw new IllegalStateException(dir.getName() + " is not a directory.");
  }
}
origin: redisson/redisson

/**
 * Creates a new iterator representation for all files within a folder.
 *
 * @param folder The root folder.
 */
protected FolderIterator(File folder) {
  files = new LinkedList<File>(Collections.singleton(folder));
  File candidate;
  do {
    candidate = files.removeFirst();
    File[] file = candidate.listFiles();
    if (file != null) {
      files.addAll(0, Arrays.asList(file));
    }
  } while (!files.isEmpty() && (files.peek().isDirectory() || files.peek().equals(new File(folder, JarFile.MANIFEST_NAME))));
}
origin: gocd/gocd

private void setUpApplicationSupport() throws IOException {
  File applicationSupport = new File(APPLICATION_SUPPORT_PATHNAME);
  applicationSupport.mkdirs();
  if (!applicationSupport.isDirectory()) {
    throw new IOException(
        "Could not create folder " + APPLICATION_SUPPORT_PATHNAME +
            ". Please check the permission settings for folder " + applicationSupport.getParentFile().getAbsolutePath());
  }
}
origin: lets-blade/blade

/**
 * Filter the file rules
 *
 * @param file
 * @param recursive
 * @return
 */
private File[] accept(File file, final boolean recursive) {
  // Custom filtering rules If you can loop (include subdirectories) or is the end of the file. Class (compiled java class file)
  return file.listFiles(file1 -> (recursive && file1.isDirectory()) || (file1.getName().endsWith(".class")));
}
origin: prestodb/presto

private URLClassLoader buildClassLoader(String plugin)
    throws Exception
{
  File file = new File(plugin);
  if (file.isFile() && (file.getName().equals("pom.xml") || file.getName().endsWith(".pom"))) {
    return buildClassLoaderFromPom(file);
  }
  if (file.isDirectory()) {
    return buildClassLoaderFromDirectory(file);
  }
  return buildClassLoaderFromCoordinates(plugin);
}
origin: hs-web/hsweb-framework

  public static FileInfo from(File file) {
    FileInfo info = new FileInfo();
    info.setName(file.getName());
    info.setLength(file.length());
    info.setParent(file.getParent());
    info.setAbsolutePath(file.getAbsolutePath());
    info.setFile(file.isFile());
    info.setDir(file.isDirectory());
    return info;
  }
}
origin: google/guava

private static Iterable<File> fileTreeChildren(File file) {
 // check isDirectory() just because it may be faster than listFiles() on a non-directory
 if (file.isDirectory()) {
  File[] files = file.listFiles();
  if (files != null) {
   return Collections.unmodifiableList(Arrays.asList(files));
  }
 }
 return Collections.emptyList();
}
origin: apache/flink

protected static void deleteRecursively(File f) throws IOException {
  if (f.isDirectory()) {
    FileUtils.deleteDirectory(f);
  } else if (!f.delete()) {
    System.err.println("Failed to delete file " + f.getAbsolutePath());
  }
}
origin: jenkinsci/jenkins

  @Override
  public boolean accept(File pathname) {
    return pathname.isDirectory() && !existing.contains(pathname.getName());
  }
})) {
origin: stackoverflow.com

 public void listFilesForFolder(final File folder) {
  for (final File fileEntry : folder.listFiles()) {
    if (fileEntry.isDirectory()) {
      listFilesForFolder(fileEntry);
    } else {
      System.out.println(fileEntry.getName());
    }
  }
}

final File folder = new File("/home/you/Desktop");
listFilesForFolder(folder);
origin: stackoverflow.com

 File f = new File("/Path/To/File/or/Directory");
if (f.exists() && f.isDirectory()) {
  ...
}
origin: libgdx/libgdx

static private boolean deleteDirectory (File file) {
  if (file.exists()) {
    File[] files = file.listFiles();
    if (files != null) {
      for (int i = 0, n = files.length; i < n; i++) {
        if (files[i].isDirectory())
          deleteDirectory(files[i]);
        else
          files[i].delete();
      }
    }
  }
  return file.delete();
}
java.ioFileisDirectory

Javadoc

Indicates if this file represents a directory on the underlying file system.

Popular methods of File

  • <init>
    Creates a new File instance by converting the givenfile: URI into an abstract pathname. The exact fo
  • exists
    Tests whether the file or directory denoted by this abstract pathname exists.
  • getAbsolutePath
    Returns the absolute pathname string of this abstract pathname. If this abstract pathname is already
  • getName
    Returns the name of the file or directory denoted by this abstract pathname. This is just the last n
  • mkdirs
  • delete
    Deletes the file or directory denoted by this abstract pathname. If this pathname denotes a director
  • listFiles
    Returns an array of abstract pathnames denoting the files and directories in the directory denoted b
  • getParentFile
    Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not
  • getPath
    Converts this abstract pathname into a pathname string. The resulting string uses the #separator to
  • isFile
  • length
    Returns the length of the file denoted by this abstract pathname. The return value is unspecified if
  • toURI
  • length,
  • toURI,
  • createTempFile,
  • createNewFile,
  • toPath,
  • mkdir,
  • lastModified,
  • toString,
  • getCanonicalPath

Popular in Java

  • Running tasks concurrently on multiple threads
  • findViewById (Activity)
  • setRequestProperty (URLConnection)
  • getSharedPreferences (Context)
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • KeyStore (java.security)
    KeyStore is responsible for maintaining cryptographic keys and their owners. The type of the syste
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the
  • JLabel (javax.swing)
  • JOptionPane (javax.swing)
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now