Visualizzazione dei risultati da 1 a 9 su 9
  1. #1

    [java] elencare files presenti in una directory

    come farlo in modo semplice e veloce?

  2. #2
    Perchè non leggere i post precedenti??
    http://forum.html.it/...?s=&threadid=756974
    Lang=Java
    Ambiente = Eclipse forever
    Ubuntu & Win XP Pro

  3. #3
    non mi va un granchè...siamo sicuri?...e poi in questo modo non posso passargli la lunghezza dell'array..

  4. #4
    ah?
    La lunghezza dell'array la ottieni dopo che hai richiamato il metodo della classe File .
    Inoltre puoi applicare un FileFilter per scegliere solo i file che ti interessano.
    Lang=Java
    Ambiente = Eclipse forever
    Ubuntu & Win XP Pro

  5. #5

  6. #6

  7. #7
    Scusami
    codice:
    File[] lista=new File("c:\Windows").listFiles();
    oppure 
    File[] lista=new File("c:\Windows").listFile(new FileFilter(){
        public boolean accept(File file){
            if(file.isDir()) return true;
            if(file.getName().endsWith(".exe"))
                return true;
            return false;
        }
    
    });
    for(int i=0;i<lista.length;i++)
          System.out.println(lista[i]);
    Lang=Java
    Ambiente = Eclipse forever
    Ubuntu & Win XP Pro

  8. #8
    Utente di HTML.it L'avatar di morphy79
    Registrato dal
    Jun 2004
    Messaggi
    1,568
    e se ho un pattern di file da filtrare come faccio ???
    odio chi parla di politica..
    anzi vorrei fondare un partito contro tutto ciò

  9. #9
    Questa classe stampa su file tutti i file contenuti in una cartella considerando anche le varie ramificazioni della stasse.

    Se ti può essere utile!!!

    codice:
    import java.io.*; 
    import javax.swing.JOptionPane; 
    
    public class RicercaFile { 
    
        public static void main( String[] args )
        { 
            String path = JOptionPane.showInputDialog( null,"Inserisci il path", "Input path", JOptionPane.INFORMATION_MESSAGE ); 
    
            if( ( path == null ) ||( path.equals( "" ) ) )
                { 
                JOptionPane.showMessageDialog( null,"Dovevi inserire un path", "Errore", JOptionPane.ERROR_MESSAGE ); 
                System.exit( 0 ); 
                } 
         try{
            String fw = "c:\\LogFile.txt";
            PrintStream scrivi = new PrintStream(new FileOutputStream(fw));
            mostra(path,scrivi);
            scrivi.close();
            } catch(IOException e){}
    
            System.exit( 1 ); 
    
        }
            
        public static void mostra(String path, PrintStream scrivi)    
        {
        try{
            File f = new File( path ); 
            File[] contenuto = f.listFiles(); 
            
            if(contenuto.length != 0)
                {
                for( int i = 0; i < contenuto.length; i++ )
                    { 
                    if( contenuto[i].isDirectory() )
                        { 
                        mostra(contenuto[i].getPath(),scrivi); 
                        } 
                    } 
    
                for( int i = 0; i < contenuto.length; i++ )
                    { 
                    if( contenuto[i].isFile() )
                        { 
                        String dim = contenuto[i].getPath();
                        System.out.println(contenuto[i].getPath() + ";" + contenuto[i].length()/1024 + ";"  +  dim.length() );
                        scrivi.println(contenuto[i].getPath() + ";" + contenuto[i].length()/1024 + ";" + dim.length());
    
                        } 
                    } 
                }
            else
                {
                 JOptionPane.showMessageDialog( null, path + ": non ha files", "Attenzione", JOptionPane.INFORMATION_MESSAGE ); 
                }
        } catch(Exception e)
            {
                JOptionPane.showMessageDialog( null, path + ": Exception: " + e, "Attenzione", JOptionPane.INFORMATION_MESSAGE ); 
             }
        }
     
    }

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.