Java tutorial
//package com.java2s; import java.io.File; import java.util.HashMap; public class Main { /** * Gets the directory files list. * * @param directory * the directory * @return the directory files list */ public static HashMap<String, File> getDirectoryFilesList(String directory) { return getDirectoryFilesList(new File(directory)); } /** * Gets the directory files list. * * @param directory * the directory * @return the directory files list */ public static HashMap<String, File> getDirectoryFilesList(File directory) { final HashMap<String, File> directoryList = new HashMap<String, File>(); if (directory == null) { return directoryList; } if (!directory.exists()) { return directoryList; } if (directory.isDirectory()) { final String[] list = directory.list(); // Some JVMs return null for File.list() when the // directory is empty. if (list != null) { for (final String element : list) { final File entry = new File(directory, element); if (!entry.isDirectory()) { String name = entry.getName(); if (name.length() > 0 && name.contains(".")) { name = (String) name.subSequence(0, name.lastIndexOf('.')); directoryList.put(name, entry); } } } } } return directoryList; } }