Get a list of all files in directory that have passed prefix.

@param dir Dir to look in.
@param prefix Basename of files to look for. Compare is case insensitive.

@return List of files in dir that start w/ passed basename.
357717
public static File [] getFilesWithPrefix(File dir, final String prefix) {
        FileFilter prefixFilter = new FileFilter() {
                public boolean accept(File pathname)
                {
                    return pathname.getName().toLowerCase().
                        startsWith(prefix.toLowerCase());
                }
            };
        return dir.listFiles(prefixFilter);
    }
1087227
private void getDescFiles(File dir, Collection<File> files) {
        if (dir.isDirectory()) {
            for (File file : dir.listFiles()) {
                if (file.isDirectory()) {
                    getDescFiles(file, files);
                } else if (file.getName().equals(DESC)) {
                    files.add(file);
                }
            }
        }
    }
906183
public static List<File> getDirectoriesByName(String root) {
        if (root == null || root.length() == 0)
            return Collections.emptyList();

        return getDirectories(new File(root));
    }
564967
private static Collection<File> findDirsRecursively(File dir) {
		return FileUtils.listFilesAndDirs(dir, FalseFileFilter.FALSE, TrueFileFilter.TRUE);
	}
446844
public Map<String, V> prefix(@NonNull String prefix) {
      final TrieNode<V> match = root.find(prefix);
      if (match == null) {
         return Collections.emptyMap();
      }
      return new AbstractMap<String, V>() {
         @Override
         public Set<Entry<String, V>> entrySet() {
            return new AbstractSet<Entry<String, V>>() {
               @Override
               public Iterator<Entry<String, V>> iterator() {
                  return Iterators.unmodifiableIterator(new EntryIterator<>(match));
               }

               @Override
               public int size() {
                  return match.size;
               }
            };
         }
      };
   }
875509
private static File[] loadXmlFiles(final File directory) {
		return directory.listFiles(new FileFilter() {

			@Override
			public boolean accept(File file) {
				return file.getName().endsWith(".xml");
			}

		});
	}
408859
public final Collection<File> findFiles(File directory, FileFilter filter) {
		final Collection<File> files = new ArrayList<>();
		findFiles(directory, filter, files);
		return files;
	}
565717
public static File[] listExtensions(String extensionDir) {
    File[] extensions = new File(extensionDir)
        .listFiles(file -> file.getPath().toLowerCase().endsWith(Constants.EXTENSION_JAR));
    if (extensions == null) {
      // Directory does not exist
      return EMPTY_EXTENSIONS_LIST;
    }
    return extensions;
  }
189460
public static function parse_dir( $path, $extension, $prefix = '' ) {
		$extension = ltrim( $extension, '.' );
		$regexp = '#/([^._][^/]*)\.' . $extension . '$#u';
		if ( ! is_dir( $path ) ) {
			return [];
		}
		$files = [];
		$finder = new Finder();
		foreach ( $finder->in( $path )->name( "*.{$extension}" )->files() as $file ) {
			$file_path = $file->getPathname();
			if ( ! preg_match( $regexp, $file_path, $match ) ) {
				continue;
			}
			$handle = $prefix . $match[1];
			$deps = self::grab_deps( $file_path );
			$url = str_replace( ABSPATH, home_url( '/' ), $file_path );
			$files[ $handle ] = [
				'path' => $file_path,
				'deps' => $deps,
				'url'  => $url,
			];
		}
		return $files;
	}
68245
public static List<String> getKeys(String prefix) {
        List<String> res = new ArrayList<>();
        for(String key: props.keySet()){
            if(key.startsWith(prefix)){
                res.add(key);
            }
        }
        return res;
    }
475939
private static File[] getAllFiles(String dirName) {

    File dir = new File(dirName);

    File[] files = dir.listFiles(); // returns files and folders

    if (files != null) {
      List<File> filteredFiles = new ArrayList<File>();
      for (File file : files) {

        if (file.isFile()) {
          filteredFiles.add(file);
        }
      }
      return filteredFiles.toArray(new File[filteredFiles.size()]);
    } else {
      System.out.println(dirName + " does not denote a valid directory!");
      return new File[0];
    }
  }
1329030
public static List<File> listDirs(final File dir)
	{
		final List<File> foundedDirs = new ArrayList<>();
		final File[] fileArray = dir.listFiles();
		for (final File element : fileArray)
		{
			if (element.isDirectory())
			{
				foundedDirs.add(element);
			}
		}
		return foundedDirs;

	}
702136
public static boolean deleteDirectory(final File dir) {
		boolean success = true;
		if (dir != null && dir.exists()) {
			try {
				if (dir.isDirectory()) {
					for (final File file : dir.listFiles()) {
						if(file == null) {
							return false;
						}
						if (!deleteDirectory(file)) {
							success = false;
							return success;
						}
					}
				}
				if (!dir.delete()) {
					success = false;
					return success;
				}
				return success;
			} catch (Exception e) {
				// Failed to delete files or directory
			}
		}
		return false;
	}
1350885
def list_files(self, prefix, flat):
    

    layer_path = self.get_path_to_file("")        
    path = os.path.join(layer_path, prefix) + '*'

    filenames = []

    remove = layer_path
    if len(remove) and remove[-1] != '/':
      remove += '/'

    if flat:
      for file_path in glob(path):
        if not os.path.isfile(file_path):
          continue
        filename = file_path.replace(remove, '')
        filenames.append(filename)
    else:
      subdir = os.path.join(layer_path, os.path.dirname(prefix))
      for root, dirs, files in os.walk(subdir):
        files = [ os.path.join(root, f) for f in files ]
        files = [ f.replace(remove, '') for f in files ]
        files = [ f for f in files if f[:len(prefix)] == prefix ]
        
        for filename in files:
          filenames.append(filename)
    
    def stripgz(fname):
      (base, ext) = os.path.splitext(fname)
      if ext == '.gz':
        return base
      else:
        return fname

    filenames = list(map(stripgz, filenames))
    return _radix_sort(filenames).__iter__()
29253
private static List<Path> file_listing_(Path dir) throws IOException {
        try (Stream<Path> files = Files.list(dir)) {
            return files.collect(Collectors.toList());
        }
    }
815122
private static String recursiveSearch(java.io.File dir, String fileName) {
        for (String name : dir.list()) {
            java.io.File file = new java.io.File(dir.getAbsolutePath() + "/" + name);
            if (name.compareTo(fileName) == 0) return file.getAbsolutePath();
            if (file.isDirectory()) {
                String filePath = recursiveSearch(file, fileName);
                if (filePath != null) return filePath;
            }
        }

        return null;
    }
591946
public static List<File> getFilesByExtension(File dir, String[] extensions)
    {
        if (!dir.isDirectory() || extensions == null)
            return Collections.emptyList();
        List<File> files = new ArrayList<File>();
        addFilesByExtension(files, dir, extensions);
        return files;
    }