Here you can find the source of getFileNames(String path, boolean withFullPath)
Parameter | Description |
---|---|
path | a parameter |
withFullPath | a parameter |
public static String[] getFileNames(String path, boolean withFullPath)
//package com.java2s; /*/*w w w . jav a 2 s . com*/ * Copyright (c) 2012 Diamond Light Source Ltd. * * 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 */ import java.io.File; import java.io.FilenameFilter; import java.util.Arrays; public class Main { /** * Returns a string array of file names in a path directory, with or without * the full path * * @param path * @param withFullPath * @return string array */ public static String[] getFileNames(String path, boolean withFullPath) { File dir = new File(path); String[] children = dir.list(); if (children == null) { return null; } // We filter any files that start with '.' or directory FilenameFilter filter = new FilenameFilter() { @Override public boolean accept(File dir, String name) { File f = new File(dir.getAbsolutePath() + "/" + name); if (f.isDirectory()) return false; return !name.startsWith("."); } }; children = dir.list(filter); Arrays.sort(children); if (withFullPath) { for (int i = 0; i < children.length; i++) { children[i] = path + "/" + children[i]; } } return children; } }