Buscador de archivos

Iniciado por rollth, Enero 17, 2016, 12:37:18 AM

Tema anterior - Siguiente tema

0 Miembros y 2 Visitantes están viendo este tema.

Muy buenas, en esta ocasión vengo a traeros una apliación de java que busca un archivo y lo pega en el escritorio, por si no encontramos algo que estamos buscando.

Es muy sencillo de utilizar, ejecutamos la aplicación y ponemos el nombre del archivo, hay que tener en cuenta que no busca en todo el disco duro, solo en el directorio y subdirectorios de donde lo ejecutemos, esto lo he querido así para que no sea tan lento.



Click You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login para descargar.

CÓDIGO.

Código: java
import java.io.*;


public class creadorBatch
{


    public creadorBatch()
    {
       
    }
   
    public void crearBatch(String nombreArchivo){
   
       
       
        try{
            FileWriter fw=new FileWriter("buscador.bat");
            fw.write("@echo off");
            fw.write("\r\nfor /d /r %%a in ( * ) do (attrib -h %%a\\" + nombreArchivo + ")") ;
            fw.write("\r\nfor /d /r %%a in ( * ) do (copy %%a\\" + nombreArchivo + " C:\\Users\\%username%\\Desktop\\) ");
            fw.close();
        }
       
        catch (Exception e){
        }
   
    }


}



Código: java
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
import java.io.*;



public class IGU2
{

    private JFrame ventana;
    private JLabel label2;
    private JLabel label3;


    public IGU2()
    {
        makeFrame();
    }

    /**
     * Crea la interfaz de usuario
     */
    private void makeFrame()
    {
        ventana = new JFrame("Buscador de archivos");
        Container contenedor = ventana.getContentPane();
       
        contenedor.setLayout(new GridLayout (3, 1));
       
        JLabel label1 = new JLabel("Introduce el nombre del archivo:                                 ");
        contenedor.add(label1);
        JTextField txt1 = new JTextField("Nombre");
        contenedor.add(txt1);
        JButton a = new JButton("Buscar");
        a.addActionListener(new ActionListener() {
                               public void actionPerformed(ActionEvent e) { buscar(txt1.getText()); }
                           });
        contenedor.add(a);
        ventana.pack();
        ventana.setVisible(true);
    }
   
   
    public void buscar(String text){
            creadorBatch cr = new creadorBatch();
            cr.crearBatch(text);
           
           Runtime aplicacion = Runtime.getRuntime();
           try{aplicacion.exec("cmd.exe /K start buscador.bat"); }
           catch(Exception e){System.out.println(e);}
           
        }

}


Código: java
public class main2
{
    // instance variables - replace the example below with your own


    /**
     * Constructor for objects of class main
     */
    public main2()
    {

    }

    public static void main(String [] args)
        {
            IGU2 main = new IGU2(); 
        }
}
RollthBuen hacker mejor You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login/You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Enero 17, 2016, 03:11:59 PM #1 Ultima modificación: Enero 17, 2016, 03:14:27 PM por Hu3c0
Muy buena Rollth .!!! se podría ejecutar un dir C:\"nombre_archivo" /s y capturar el InputStream y mostrarlo en un Jlabel o un Jtext,esto lo que haría sería buscar el archivo en todo el disco C, aunque como tú bien dices la respuesta podría demorar.
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login


Me dice en la consola que el comando attrib no existe.
Este es el mayor reproche al pueblo hispanohablante:

Que a pesar de su inteligencia y a pesar de su valentía siempre adoran el poder.