Advertisement
Guest User

Untitled

a guest
Jun 11th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 KB | None | 0 0
  1. private JButton getJButton() {
  2.         if (jButton == null) {
  3.             jButton = new JButton();
  4.             jButton.setText("Exportar");
  5.             jButton.addActionListener(new java.awt.event.ActionListener() {
  6.                 public void actionPerformed(java.awt.event.ActionEvent e) {
  7.                    
  8.  
  9.                       File raiz = new File("C:"); //tiene que ser carpeta
  10.                       resultados = new ArrayList<File>();//limpia la lista de resultados al comenzar
  11.                       buscar(raiz,"mysqldump.exe");
  12.                       mostrarResultados();
  13.                          
  14.                    
  15.                    
  16.                     /*getClass()
  17.                     String cmd="mysqldump --password=CLCadmin --user=adminCLC playacruzroja > playacruzroja.sql";
  18.                     try {
  19.  
  20.                     //Creamos el proceso
  21.                     Process p=Runtime.getRuntime().exec(cmd);  
  22.                     //Esperamos a que acabe para ejecutar el siguiente
  23.                     // p.waitFor();
  24.  
  25.  
  26.                     } catch (IOException ex) {
  27.                     ex.printStackTrace();
  28.                     }
  29.                     */
  30.                 }
  31.             });
  32.         }
  33.         return jButton;
  34.     }
  35.    
  36.     //imprime los archivos encontrados
  37.     private void mostrarResultados(){
  38.       for(File archivo : resultados){
  39.         System.out.println(archivo.getAbsolutePath());
  40.       }
  41.     }
  42.     //agrega un archivo a la lista de resultados
  43.     private void addResultado(File archivo){
  44.       resultados.add(archivo);
  45.     }
  46.     private void buscar(File raiz, String sentencia){
  47.       if(!raiz.isDirectory()){
  48.         throw new IllegalArgumentException("Archivo raiz no es una carpeta");
  49.       }
  50.       File[] archivos = raiz.listFiles();
  51.       for(int i=0; i<archivos.length; i++){
  52.         File archivo = archivos[i];
  53.         //si es directorio comenzamos la busqueda en ese directorio
  54.         if(archivo.isDirectory()){
  55.           buscar(archivo, sentencia);
  56.         }
  57.         //solo compara contra el nombre del archivo
  58.         if(archivo.getName().matches(sentencia)){
  59.           addResultado(archivo);
  60.         }
  61.       }
  62.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement