1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
public class Main {
public static void main(String[] args) throws IOException, BiffException {
Workbook workbook = Workbook.getWorkbook(new File("E:\\Base_nouvelles_image_ Jofl_complète_TRAVAIL_marco_fait2.xls"));
Sheet sheet = workbook.getSheet(0);
Cell cell = null;
for(int j = 1; j < sheet.getRows();j++ ) {
cell = sheet.getCell(7,j);
}
File dossier = new File("E:\\TOUT_ENSEMBLE_REF_NASA_GALAXY_CONCATENEES");
File[] liste = dossier.listFiles();
for (int i = 0; i < liste.length; i++) {
if (liste[i].isFile()) { // Si c'est un fichier
// Recupere les fichiers en cours
File f = new File("E:\\TOUT_ENSEMBLE_REF_NASA_GALAXY_CONCATENEES"+liste[i].getName());
String extension = "";
String ancien = liste[i].getName();
// Verifie que l'extension est un point .jpg
int index = ancien.lastIndexOf('.');
if (index > 0) {
extension = ancien.substring(index+1);
//System.out.println(extension);
}
if (extension.equals("jpg")) {
String nouveau = cell.getContents()+i+".jpg";
f.renameTo(new File("E:\\TOUT_ENSEMBLE_REF_NASA_GALAXY_CONCATENEES"+nouveau));
System.out.println(ancien+" renomme => " +nouveau);
}
else {
System.out.println(ancien+" n'est pas un fichier image");
}
}
}
workbook.close();
}
} |
Partager