Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private JButton getJButton() {
- if (jButton == null) {
- jButton = new JButton();
- jButton.setText("Exportar");
- jButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent e) {
- File raiz = new File("C:"); //tiene que ser carpeta
- resultados = new ArrayList<File>();//limpia la lista de resultados al comenzar
- buscar(raiz,"mysqldump.exe");
- mostrarResultados();
- /*getClass()
- String cmd="mysqldump --password=CLCadmin --user=adminCLC playacruzroja > playacruzroja.sql";
- try {
- //Creamos el proceso
- Process p=Runtime.getRuntime().exec(cmd);
- //Esperamos a que acabe para ejecutar el siguiente
- // p.waitFor();
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- */
- }
- });
- }
- return jButton;
- }
- //imprime los archivos encontrados
- private void mostrarResultados(){
- for(File archivo : resultados){
- System.out.println(archivo.getAbsolutePath());
- }
- }
- //agrega un archivo a la lista de resultados
- private void addResultado(File archivo){
- resultados.add(archivo);
- }
- private void buscar(File raiz, String sentencia){
- if(!raiz.isDirectory()){
- throw new IllegalArgumentException("Archivo raiz no es una carpeta");
- }
- File[] archivos = raiz.listFiles();
- for(int i=0; i<archivos.length; i++){
- File archivo = archivos[i];
- //si es directorio comenzamos la busqueda en ese directorio
- if(archivo.isDirectory()){
- buscar(archivo, sentencia);
- }
- //solo compara contra el nombre del archivo
- if(archivo.getName().matches(sentencia)){
- addResultado(archivo);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement