Java Code Examples for java.io.File.listFiles()

The following are Jave code examples for showing how to use listFiles() of the java.io.File class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: convertigo-engine   File: TracePlayerManager.java   View Source Code Vote up 6 votes
public Collection<String> getEtr(){
	Collection<File> res = new LinkedList<File>();
	File[] listdir = new File(Engine.PROJECTS_PATH).listFiles();
	for(File s : listdir){
		File tracedir = new File(s,"Traces");
		if(tracedir.exists()&&tracedir.isDirectory()){
			File[] listconnectors = tracedir.listFiles();
			for(File s2 : listconnectors){
				res.addAll(Arrays.asList(s2.listFiles(new FilenameFilter(){
					public boolean accept(File arg0, String arg1) {
						return arg1.endsWith(".etr");
					}
				})));
			}
		}
	}
	Collection<String> listetr = new ArrayList<String>(res.size());
	for(File f : res)
		listetr.add(f.getPath().substring(Engine.PROJECTS_PATH.length()));
	return listetr;
}
 
Example 2
Project: Selector   File: DataCleanManager.java   View Source Code Vote up 6 votes
public static long getFolderSize(File file) throws Exception {
  long size = 0;
  try {
    File[] fileList = file.listFiles();
    for (int i = 0; i < fileList.length; i++) {
      // 如果下面还有文件
      if (fileList[i].isDirectory()) {
        size = size + getFolderSize(fileList[i]);
      } else {
        size = size + fileList[i].length();
      }
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
  return size;
}
 
Example 3
Project: pivaa   File: Digest.java   View Source Code Vote up 6 votes
private void run(final String prefix, final MessageDigest messageDigest) throws IOException {
    if (inputs == null) {
        println(prefix, DigestUtils.digest(messageDigest, System.in));
        return;
    }
    for(final String source : inputs) {
        final File file = new File(source);
        if (file.isFile()) {
            println(prefix, DigestUtils.digest(messageDigest, file), source);
        } else if (file.isDirectory()) {
            final File[] listFiles = file.listFiles();
            if (listFiles != null) {
                run(prefix, messageDigest, listFiles);
            }
        } else {
            // use the default charset for the command-line parameter
            final byte[] bytes = source.getBytes(Charset.defaultCharset());
            println(prefix, DigestUtils.digest(messageDigest, bytes));
        }
    }
}
 
Example 4
Project: util4j   File: AbstractLibScriptFactory.java   View Source Code Vote up 6 votes
/**
 * 寻找目录下的jar文件
 * @param scriptLibDir
 * @return
 */
protected List<File> findJarFile(String scriptLibDir) {
	List<File> files = new ArrayList<File>();
	try {
		File file = new File(scriptLibDir);
		if (file.isDirectory()) {
			for (File f : file.listFiles()) {
				if (f.isFile() && f.getName().endsWith(".jar")) {
					files.add(f);
				}
			}
		}
	} catch (Exception e) {
		_log.error(e.getMessage(), e);
	}
	return files;
}
 
Example 5
Project: MyAnimeViewer   File: FileUtils.java   View Source Code Vote up 6 votes
public static long getFolderSize(File dir) {
    if (dir.exists()) {
        long result = 0;
        File[] fileList = dir.listFiles();
        for (int i = 0; i < fileList.length; i++) {
            // Recursive call if it's a directory
            if (fileList[i].isDirectory()) {
                result += getFolderSize(fileList[i]);
            } else {
                // Sum the file size in bytes
                result += fileList[i].length();
            }
        }
        return result; // return the file size
    }
    return 0;
}
 
Example 6
Project: Pluto-Android   File: PlutoFileCache.java   View Source Code Vote up 6 votes
/**
 * 获取所有缓存文件,判断依据:文件名开头cache_并且文件名结尾.data
 *
 * @return 返回列表,长度0则为空
 */
public List<File> getAllDiskCacheFile() {
	List<File> allFiles = new ArrayList<>();
	File cacheDir = new File(Pluto.SDPATH + "cache/");

	if (cacheDir.exists()) {
		File[] files = cacheDir.listFiles();
		for (File file : files) {
			String fileName = file.getName();
			if (fileName.startsWith("cache_") && fileName.endsWith(".data")) {
				allFiles.add(file);
			}
		}
	}

	return allFiles;
}
 
Example 7
Project: atlas   File: MergeResV4Dir.java   View Source Code Vote up 6 votes
private void moveFiles(File root) throws IOException {
    if (null == root || !root.exists()) {
        return;
    }

    File[] files = root.listFiles();
    for (File tmp : files) {

        if (tmp.isDirectory() &&
                tmp.getName().startsWith("drawable-") &&
                tmp.getName().endsWith("dpi")) {
            File toDir = new File(root, tmp.getName() + "-v4");
            toDir.mkdirs();

            FileUtils.copyDirectory(tmp, toDir);
            FileUtils.deleteDirectory(tmp);
        }
    }
}
 
Example 8
Project: ramus   File: Options.java   View Source Code Vote up 6 votes
public synchronized static void clearTmp() {
    final File dir = new File(tmpPath.substring(0, tmpPath.length() - 1));
    final File l = dir;
    if (l.isDirectory() && !".".equals(l.getName())
            && !"..".equals(l.getName())) {
        boolean rem = true;
        final File[] fs = l.listFiles();
        for (final File f : fs) {
            if (f.getName().equals(".locked")) {
                if (!f.delete())
                    rem = false;
            }
        }
        if (rem)
            recRomove(l);
    }
    dir.delete();
}
 
Example 9
Project: MeziLang   File: PathUtil.java   View Source Code Vote up 5 votes
public static boolean clearFilesOnPath(String path) {
  File dir = new File(path);

  if (!dir.exists()) {
    System.out.println(path + " does not exists");
    return false;
  }

  if (!dir.isDirectory()) {
    System.out.println(path + " is not directory");
    return false;
  }

  File[] files = dir.listFiles();

  System.out.println("deleting " + path + " (" + files.length + " files)");

  for (int i = 0; i < files.length; i++) {
    if (files[i].isFile()) {
      // System.out.println("deleting " + files[i] );
      if (!files[i].delete()) {
        return false;
      }
    }
  }

  return true;
}
 
Example 10
Project: dacapobench   File: TPCC.java   View Source Code Vote up 5 votes
private static boolean deleteDirectory(File path) {
  if (path.exists()) {
    File[] files = path.listFiles();
    for (int i = 0; i < files.length; i++) {
      if (files[i].isDirectory()) {
        deleteDirectory(files[i]);
      } else {
        files[i].delete();
      }
    }
  }
  return path.delete();
}
 
Example 11
Project: SkinFixer   File: SkinInstaller.java   View Source Code Vote up 5 votes
@Override
public void actionPerformed(ActionEvent e) {
    String action = e.getActionCommand();

    if(action.equals(VERSION_CHOOSER)) {
        File mc = new File(minecraftPath.getText());
        File versions = new File(mc, "versions");

        JDialog dialog = new JDialog();

        dialog.setTitle("Select a Version");
        dialog.setLayout(new GridBagLayout());

        GridBagConstraints c = new GridBagConstraints();
        c.insets = new Insets(5, 5, 5, 5);
        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 0;

        version = new JComboBox();
        for(File f : versions.listFiles()) {
            if(f.isDirectory()) version.addItem(f.getName());
        }
        dialog.add(version, c);

        JButton install = new JButton("Install");
        install.setActionCommand(INSTALL);
        install.addActionListener(this);
        dialog.add(install, c);

        Dimension d = dialog.getPreferredSize();
        dialog.setSize(new Dimension(d.width + 50, d.height + 50));
        dialog.setLocationRelativeTo(this);

        dialog.setVisible(true);
    } else if(action.equals(INSTALL)) {
        //TODO
    }
}
 
Example 12
Project: CXJPadProject   File: CXPFileUtils.java   View Source Code Vote up 5 votes
public static long calcDirSize(File dir) { //取得文件夹大�?
    long size = 0;
    File flist[] = dir.listFiles();
    for (int i = 0; i < flist.length; i++) {
        if (flist[i].isDirectory()) {
            size = size + calcDirSize(flist[i]);
        } else {
            size = size + flist[i].length();
        }
    }
    return size;
}
 
Example 13
Project: Coder   File: FileUtils.java   View Source Code Vote up 5 votes
/**
 * 获取目录下所有后缀名为suffix的文件
 * <p>大小写忽略</p>
 *
 * @param dir         目录
 * @param suffix      后缀名
 * @param isRecursive 是否递归进子目录
 * @return 文件链表
 */
public static List<File> listFilesInDirWithFilter(File dir, String suffix, boolean isRecursive) {
    if (isRecursive) return listFilesInDirWithFilter(dir, suffix);
    if (dir == null || !isDir(dir)) return null;
    List<File> list = new ArrayList<>();
    File[] files = dir.listFiles();
    if (files != null && files.length != 0) {
        for (File file : files) {
            if (file.getName().toUpperCase().endsWith(suffix.toUpperCase())) {
                list.add(file);
            }
        }
    }
    return list;
}
 
Example 14
Project: aliyun-maxcompute-data-collectors   File: SqoopHCatUtilities.java   View Source Code Vote up 5 votes
/**
 * Add the .jar elements of a directory to the DCache classpath, optionally
 * recursively.
 */
private static void addDirToCache(File dir, FileSystem fs,
  Set<String> localUrls, boolean recursive) {
  if (dir == null) {
    return;
  }

  File[] fileList = dir.listFiles();

  if (fileList == null) {
    LOG.warn("No files under " + dir
      + " to add to distributed cache for hcatalog job");
    return;
  }

  for (File libFile : dir.listFiles()) {
    if (libFile.exists() && !libFile.isDirectory()
      && libFile.getName().endsWith("jar")) {
      Path p = new Path(libFile.toString());
      if (libFile.canRead()) {
        String qualified = p.makeQualified(fs).toString();
        LOG.info("Adding to job classpath: " + qualified);
        localUrls.add(qualified);
      } else {
        LOG.warn("Ignoring unreadable file " + libFile);
      }
    }
    if (recursive && libFile.isDirectory()) {
      addDirToCache(libFile, fs, localUrls, recursive);
    }
  }
}
 
Example 15
Project: exciting-app   File: FileUtil.java   View Source Code Vote up 5 votes
/**
 * 根据文件夹路径,获得该路径指向的文件夹的大小。
 * 遍历该文件夹及其子目录的文件,将这些文件的大小进行累加,得出的就是文件夹的大小。
 *
 * @param path
 * @return
 * @throws FileNotFoundException
 */
public static long getFolderSize(String path) throws FileNotFoundException {
    path = separatorReplace(path);
    long size = 0;
    File folder = getFolder(path);
    File[] files = folder.listFiles();
    for (File file : files) {
        if (file.isDirectory()) {
            size += getFolderSize(file.getAbsolutePath());
        } else if (file.isFile()) {
            size += file.length();
        }
    }
    return size;
}
 
Example 16
Project: FJ-VDMJ   File: SpecificationReader.java   View Source Code Vote up 5 votes
/**
 * Parse and type check source files, and create an interpreter. Directories are
 * expanded to include any VDM source files they contain.
 * 
 * @param charset The charset for the specification files.
 * @param filenames A list of VDM source files or directories.
 * @throws Exception 
 */
public Interpreter readSpecification(Charset charset, String... filenames) throws Exception
{
	List<File> list = new Vector<File>(filenames.length);
	
	for (String filename: filenames)
	{
		URL url = getClass().getResource("/" + filename);
		
		if (url == null)
		{
			throw new FileNotFoundException(filename);
		}
		
		File file = new File(url.getFile());
		
		if (file.isDirectory())
		{
			for (File subfile: file.listFiles(Settings.dialect.getFilter()))
			{
				if (subfile.isFile())
				{
					list.add(subfile);
				}
			}
		}
		else
		{
			list.add(file);
		}
	}
	
	return readSpecification(charset, list);
}
 
Example 17
Project: q-mail   File: LocalStore.java   View Source Code Vote up 5 votes
private void deleteAllMessagePartsDataFromDisk() {
    final StorageManager storageManager = StorageManager.getInstance(context);
    File attachmentDirectory = storageManager.getAttachmentDirectory(
            account.getUuid(), database.getStorageProviderId());
    File[] files = attachmentDirectory.listFiles();
    if (files == null) {
        return;
    }

    for (File file : files) {
        if (file.exists() && !file.delete()) {
            file.deleteOnExit();
        }
    }
}
 
Example 18
Project: sumo   File: AddImageAction.java   View Source Code Vote up 4 votes
/**
* 
* @param file
* @param filter
* @return
*/
   public File listFiles(File file, String filter) {
       File[] entries = file.listFiles();

       for (File listfile : entries) {
           if (listfile.isDirectory()) {
               File filteredfile = null;
               filteredfile = listFiles(listfile, filter);
               if (filteredfile != null) {
                   return filteredfile;
               }
           } else {
               String listfilename = listfile.getName();
               String[] strings = filter.split("\\*");
               int found = 0;
               int index = 0;
               for (String string : strings) {
                   if (index == 0) {
                       if (listfilename.startsWith(string)) {
                           found++;
                           listfilename = listfilename.substring(string.length());
                       } else {
                           break;
                       }
                   } else {
                       if (index == strings.length) {
                           if (listfilename.endsWith(string)) {
                               found++;
                           } else {
                               break;
                           }
                       } else {
                           if (listfile.getName().contains(string)) {
                               found++;
                               listfilename = listfilename.substring(listfilename.indexOf(string) + string.length());
                           } else {
                               break;
                           }
                       }
                   }
                   index++;
               }
               if (found == strings.length) {
                   return listfile;
               }
           }
       }
       return null;
   }
 
Example 19
Project: BaseClient   File: TextureAnimations.java   View Source Code Vote up 4 votes
public static String[] getAnimationPropertiesDir(File p_getAnimationPropertiesDir_0_)
{
    File file1 = new File(p_getAnimationPropertiesDir_0_, "anim");

    if (!file1.exists())
    {
        return null;
    }
    else if (!file1.isDirectory())
    {
        return null;
    }
    else
    {
        File[] afile = file1.listFiles();

        if (afile == null)
        {
            return null;
        }
        else
        {
            List list = new ArrayList();

            for (int i = 0; i < afile.length; ++i)
            {
                File file2 = afile[i];
                String s = file2.getName();

                if (!s.startsWith("custom_") && s.endsWith(".properties") && file2.isFile() && file2.canRead())
                {
                    Config.dbg("TextureAnimation: anim/" + file2.getName());
                    list.add("/anim/" + s);
                }
            }

            String[] astring = (String[])((String[])list.toArray(new String[list.size()]));
            return astring;
        }
    }
}
 
Example 20
Project: openjdk-jdk10   File: FileNameCompleter.java   View Source Code Vote up 4 votes
public int complete(String buffer, final int cursor, final List<CharSequence> candidates) {
    // buffer can be null
    checkNotNull(candidates);

    if (buffer == null) {
        buffer = "";
    }

    if (OS_IS_WINDOWS) {
        buffer = buffer.replace('/', '\\');
    }

    String translated = buffer;

    File homeDir = getUserHome();

    // Special character: ~ maps to the user's home directory
    if (translated.startsWith("~" + separator())) {
        translated = homeDir.getPath() + translated.substring(1);
    }
    else if (translated.startsWith("~")) {
        translated = homeDir.getParentFile().getAbsolutePath();
    }
    else if (!(new File(translated).isAbsolute())) {
        String cwd = getUserDir().getAbsolutePath();
        translated = cwd + separator() + translated;
    }

    File file = new File(translated);
    final File dir;

    if (translated.endsWith(separator())) {
        dir = file;
    }
    else {
        dir = file.getParentFile();
    }

    File[] entries = dir == null ? new File[0] : dir.listFiles();

    return matchFiles(buffer, translated, entries, candidates);
}