I want to know the amount of non-hidden items in a java folder

0

I'm doing a program which can count the amount of selected elements in a folder, this using JFileChooser.

@Override
public void actionPerformed(ActionEvent e) {

    JFileChooser selecto = (JFileChooser) e.getSource();
    String comand = e.getActionCommand();

    if (comand.equals(JFileChooser.APPROVE_SELECTION)) {

        File archivoSelect = selecto.getSelectedFile();
        JOptionPane.showMessageDialog(this, "Guardado archivo " + archivoSelect.getName());

        System.out.println("Path: "+archivoSelect.getPath());
        System.out.println("Elementos de la carpeta: "+archivoSelect.list.length);

    }
}

But I've noticed that certain folders contain hidden files created by the PC such as thumbs.db files and this causes the program to deliver a number of files that do not match those seen simple you saw, so my question would be how to prevent the program from counting the hidden files.

I appreciate any help.

    
asked by Getsuga Tenshou 08.01.2018 в 17:45
source

1 answer

0

Use the following:

int cuenta=0;
JFileChooser selecto =new JFileChooser();
String comand = e.getActionCommand();
if (comand.equals(JFileChooser.APPROVE_SELECTION)) {
   File rutaActual=selecto.getSelectedFile();
   File [] archivos=rutaActual.listFiles();
   for(int i=0;i<archivos.length ;i++){
       if(!archivos[i].isHidden()){
          cuenta++;
       }
   }
   JOptionPane.showMessageDialog(this,"Guardado archivo "+ rutaActual.getName());
   System.out.println("Path: "+rutaActual.getPath());
   System.out.println("Elementos de la carpeta:+cuenta);
}
    
answered by 08.01.2018 / 21:42
source