fork download
  1. import java.io.*;
  2. import java.nio.file.*;
  3. import java.util.*;
  4. import java.util.regex.*;
  5.  
  6. public class Main {
  7.  
  8. public static void main(String[] args) throws IOException {
  9. Pattern ptn = Pattern.compile("^(.*?)(\\d+)(\\.[^.]*)?$");
  10. Files.list(Paths.get(""))
  11. .map(p -> ptn.matcher(p.getFileName().toString()))
  12. .filter(Matcher::matches)
  13. .forEach(m -> {
  14. String r = m.group(1)
  15. + String.format("%3s", m.group(2)).replace(' ', '0')
  16. + Objects.toString(m.group(3), "");
  17. new File(m.group(0)).renameTo(new File(r));
  18. });
  19. }
  20.  
  21. }
Success #stdin #stdout 0.08s 34720KB
stdin
Standard input is empty
stdout
Standard output is empty