Hello probleme de boucle, je ne comprends pas
je suis un peu en panique,
je dois utiliser ce petit prog pour passer dans beaucoup de dossiers,
je n'ai pas de probleme dans le prog écrit sans la boucle
Code:
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 44 45 46 47 48 49 50 51 52 53 54 55 56
|
public static void checkIfEnoughFilesfor1(String PathOriginFolder,String pathDestinationFolder, int selectParDossier) throws IOException {
String Lepatha = PathOriginFolder;
String Lepath2a = pathDestinationFolder;
System.out.println("le dossier d'origine: "+ Lepatha);
System.out.println("le dossier de destination: "+ Lepath2a);
File dir = new File(Lepath2a);
File dirOrig = new File(Lepatha);
int nbrSelecionesa = selectParDossier;
System.out.println("nombre de photos necessaires: "+ nbrSelecionesa);
String[] files = dir.list();
String[] filesOrig = dirOrig.list();
System.out.println( "Nombres d'images dans le dossier MEO: "+files.length);
List<Integer> hazardNumbers = new ArrayList<>();
int nbrrestant= nbrSelecionesa-files.length;
System.out.println("le nombre de files necessaire est "+nbrrestant);
for(int iab=0; iab<nbrrestant;){
int idz=(int)(Math.random()*filesOrig.length);
//System.out.println(idz);
if (filesOrig[idz].endsWith(".JPG")) {
if (!hazardNumbers.contains(idz)) {
hazardNumbers.add(idz);
}
}
iab++;
}
System.out.println("les photos choisies au Hasard: "+ hazardNumbers);
Desktop.getDesktop().open(dir);
Desktop.getDesktop().open(dirOrig);
for (int i = 0; i < nbrrestant;i++ ) {
Path temp = Files.move (Paths.get(PathOriginFolder+"\\"+filesOrig[hazardNumbers.get(i)]),
Paths.get(pathDestinationFolder+"\\"+filesOrig[hazardNumbers.get(i)]));
}
} |
Donc j'ai mis une boucle et j'ai une exception
Code:
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
public void checkIfEnoughFilesForM(String nomDossier3) throws Exception {
String ND3=nomDossier3;
Table t3 = CreateMDirectory(ND3);
//System.out.println(t3.columnNames());
t3.sortAscendingOn("Nom fichier");
//System.out.println(t3);
DoubleColumn nc = DoubleColumn.create("nombreDePhotos",t3.rowCount());
t3.addColumns(nc);
String input;
double selectParDossier=0;
for (int i = 0; i <2 ; i++) { //t3.rowCount()
String Lepatha = t3.get(i, 1).toString();
String Lepath2a = t3.get(i, 3).toString();
System.out.println("le dossier d'origine: "+ Lepatha);
System.out.println("le dossier de destination: "+ Lepath2a);
Scanner myObj = new Scanner(System.in);
System.out.println("Entre le nombre necessaire de photos:");
double nbrphnec = myObj.nextDouble();
nc.set(i,nbrphnec);
File dir = new File(Lepath2a);
File dirOrig = new File(Lepatha);
double nbrSelecionesa = nbrphnec;
System.out.println("nombre de photos necessaires: "+ nbrSelecionesa);
String[] files = dir.list();
String[] filesOrig = dirOrig.list();
System.out.println( "Nombres d'images dans le dossier MEO: "+files.length);
List<Integer> hazardNumbers = new ArrayList<>();
int nbrrestant= (int) (nbrSelecionesa-files.length);
System.out.println("le nombre de files necessaire est "+nbrrestant);
for(int iab=0; iab<nbrrestant;){
int idz=(int)(Math.random()*filesOrig.length);
if (filesOrig[idz].endsWith(".JPG")) {
if (!hazardNumbers.contains(idz)) {
hazardNumbers.add(idz);
}
}
iab++;
}
System.out.println("les photos choisies au Hasard: "+ hazardNumbers);
for (int i2 = 0; i2 < nbrrestant;i2++ ) {
Path temp = Files.move (Paths.get(Lepatha+"\\"+filesOrig[hazardNumbers.get(i)]),
Paths.get(Lepath2a+"\\"+filesOrig[hazardNumbers.get(i)]));
Desktop.getDesktop().open(dir);
Desktop.getDesktop().open(dirOrig);
}
}
}
public static void main (String[]args) throws Exception
{
Main client = new Main();
//client.Create1Directory("G:\\Stock\\Arima\\","22. 渡部整形外科 MEO");
//client.CreateMDirectory("G:\\Stock\\Ishibashi");
client.checkIfEnoughFilesForM("G:\\\\Stock\\\\Ishibashi");
// client.listDirectoryInFolder("G:\\Stock\\Kinoshita");
//client.checkIfEnoughFilesfor1("G:\\Stock\\Arima\\22. 渡部整形外科 MEO","G:\\Stock\\Arima\\Selection 22. 渡部整形外科 MEO", 10);
}
} |
Le message d'erreur
Code:
1 2 3 4 5 6 7 8 9 10 11
|
Exception in thread "main" java.nio.file.NoSuchFileException: G:\Stock\Ishibashi\1.
MEO\IMG_5090.JPG
at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:85)
at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:326)
at java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:292)
at java.base/java.nio.file.Files.move(Files.java:1426)
at com.company.Main.checkIfEnoughFilesForM(Main.java:226)
at com.company.Main.main(Main.java:240) |
Je suis un peu perdu.