How to get a date for each file at the directory



  • Hello. I have a folder containing a lot of big files I don't know. I only know a relative path to the folder they're in. I need to check if they're old enough to say, like, a month and delete if they do.

    I've come up with a way to find the date of the file on his way.

    BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
            System.out.println("     creationTime: " + attr.creationTime());
    

    How do you get the name of all the ways to file? I understand.

    File myFolder = new File("путь к папке");
        File[] files = myFolder.listFiles();
    

    It's what brings the files to the program that I don't need, because the files are big and they're big.



  • This is an example of the programme being prepared:

    public class Dir {
    public static void main(String[] args)
    {
        try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(args[0]))) {
            for (Path file: stream) {
                if(!file.toFile().isDirectory() ) {
                    System.out.println(file.getFileName());
                }
            }
        } catch (IOException | DirectoryIteratorException x) {
                System.err.println(x);
        }
    }
    

    As an argument, the name of the director


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2