Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.nanothings.files;
- import java.io.File;
- import javax.swing.JOptionPane;
- /**
- *
- * @author guilherme
- */
- public class ListandoDir {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- String dir;
- dir = JOptionPane.showInputDialog("Digite o diretório a ser pesquisado: ");
- /*
- Caso queira definir o diretório por padrão é só comentar o JOptionPane.
- Obs: Mudar o diretório se o SO for Windows ou somento o usuário caso seja Linux.
- dir = "/home/guilherme";
- */
- File diretorio = new File(dir);
- File[] arquivos = diretorio.listFiles();
- int qtd = arquivos.length;
- System.out.println("Número de arquivos e diretório: "+ qtd);
- if(arquivos != null)
- {
- for(int i=0 ; i<qtd ; ++i)
- {
- File f = arquivos[i];
- if(f.isFile())
- {
- System.out.println(f.getName()+" é pasta.");
- }
- else if(f.isDirectory())
- {
- System.out.println(f.getName()+" é diretório.");
- }
- else
- {
- System.out.println("Essa bagaça nem é pasta nem arquivo! :D");
- }
- }
- }
- else
- {
- System.out.println("Pasta vazia!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment