DevOpsSauce
DevOpsSauce

Reputation: 1387

How do I bypass metadata when checking for empty folder (Java)?

I have simple directory list GUI that displays all the contents of a specified folder or file. I'm attempting to create a JOptionPane to alert a user that the folder is empty, however, an empty folder is still popping up on my JTable with 4 KB of data. I am on a Linux machine, so I am assuming this is the metadata.

This program was written using Swing, and I was required to simply add to two methods. Everything works, but I would really prefer to notify the user of an empty folder, since they most likely would not be concerned with the metadata. Here is what I tried (Note - I'm new to Swing since I'm accustomed to JavaFX):

    if(f.list().length == 0) {
      JPanel emptyPanel = new JPanel();
      JOptionPane.showMessageDialog(emptyPanel, "That Directory is empty.", "OOPS!", JOptionPane.INFORMATION_MESSAGE);
    }

Thanks for any help. By the way, "f" is the File object that was created in another method.

Upvotes: 0

Views: 165

Answers (1)

Natecat
Natecat

Reputation: 2182

If there is 1 metadata file in every folder, than the obvious solution would be to check if it was equal to one, not zero. If, however that metadata file is only sometimes there, then you could check if there was only 1 file in the list after you do the 0 check, and if there was, check if it is named as the metadata file is.

Upvotes: 1

Related Questions