public class DivideToDateFolder { public static void main(String[] args) throws IOException { String dir = "path/to/dir"; Path path = Paths.get(dir); Files.list(path).filter(p -> Files.isRegularFile(p)) .collect(Collectors.groupingBy(p -> { try { return LocalDateTime.ofInstant(Files.getLastModifiedTime(p).toInstant(), ZoneId.systemDefault()).toLocalDate(); } catch (IOException ex) { throw new RuntimeException(ex); } })) .forEach((dt, pList) -> { Path dPath = path.resolve(dt.toString()); try { Files.createDirectory(dPath); pList.stream().forEach(p -> { try { Files.move(p, dPath.resolve(p.getFileName())); } catch (IOException ex) { Logger.getLogger(DivideToDateFolder.class.getName()).log(Level.SEVERE, null, ex); } }); } catch (IOException ex) { Logger.getLogger(DivideToDateFolder.class.getName()).log(Level.SEVERE, null, ex); } }); } }