public class Art_replace { /** * @param args the command line arguments */ public static String ext; public static int MAX_FILE=30; public static void main(String[] args) throws IOException { // TODO code application logic here String c_projecte,c_imatges; String dades[]= new String[2]; String arr_img_prj[] = new String [MAX_FILE]; String arr_img_mod[] = new String [MAX_FILE]; demanar_dades (dades); c_projecte=dades[0]; c_imatges=dades[1]; File fp = new File(c_projecte); recorrer_dir_rec (fp,arr_img_prj); //System.out.println (Arrays.toString(arr_img_prj)); File fi = new File(c_imatges); recorrer_dir_rec (fi,arr_img_mod); //System.out.println (Arrays.toString(arr_img_mod)); Mostrar_informacio (arr_img_prj,arr_img_mod); } private static void Mostrar_informacio(String arr_img_proj[],String arr_img_mod[]){ int i ; String espais= " "; System.out.println ("Imatges del projecte Imatges de substitució"); System.out.println ("==================== ======================"); for (i = 0;i<arr_img_proj.length;i++){> espais = calcula_espais(arr_img_proj[i]!=null?arr_img_proj[i].length():4); System.out.printf ("%d.-%s %s %d.-%s\n",i,arr_img_proj[i],espais,i,arr_img_mod[i]); espais = " "; if (arr_img_proj[i]==null && arr_img_mod[i]==null) break; } } private static String calcula_espais (int num){ int i; String espai = " "; for (i =num;i<=23;i++) espai = espai + " "; return espai; } private static void demanar_dades (String dades[]) { Scanner sc = new Scanner(System.in); System.out.print("Introdueix la carpeta del projecte: "); dades[0] = sc.nextLine(); System.out.print("Introdueix la carpeta d'imatges: "); dades[1] = sc.nextLine(); System.out.print("Introdueix la extensió de les imatges: "); ext = sc.nextLine(); } private static void recorrer_dir_rec (File f, String arr_img[]) throws IOException{ File[] fitxers = f.listFiles(); for (int x=0;x<fitxers.length;x++){> if (fitxers[x].isFile()) guardar_imatges_dir(fitxers[x],arr_img); else if (fitxers[x].isDirectory()) recorrer_dir_rec(fitxers[x],arr_img); } } private static void guardar_imatges_dir (File f, String arr_img[]){ if (f.getName().indexOf("." + ext)!=-1){ int i=0; while (arr_img[i]!=null) i++; arr_img[i]=f.getPath(); } } private static void guardar_imatges_fitx (File f, String arr_img[]) throws FileNotFoundException, IOException{ int i=0; while (arr_img[i]!=null) i++; BufferedReader rli = new BufferedReader(new FileReader(f)); String linia = rli.readLine(); while(linia != null){ if (linia.contains("."+ext)){ arr_img[i]= recupera_nom_fitxer (linia); i++; } linia = rli.readLine(); } } private static String recupera_nom_fitxer(String linia) { int index=0; String nom_file=""; index = linia.indexOf("." + ext,index); while (linia.charAt(index)!=' ' && linia.charAt(index)!='\\'&& linia.charAt(index)!='/'){ nom_file= linia.charAt(index) + nom_file; index = index-1; } return nom_file + ext; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)