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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
|
package com.company;
import tech.tablesaw.api.DoubleColumn;
import tech.tablesaw.api.StringColumn;
import tech.tablesaw.api.Table;
import java.awt.*;
import java.io.*;
import java.io.File;
import java.nio.file.*;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public void Create1Directory(String Path33, String nomFile) throws Exception {
//Pour creer un seul dossier
File file = new File(Path33 + "Selection "+ nomFile);
if (!file.exists()) {
if (file.mkdir()) {
System.out.println("Directory is created!");
} else {
System.out.println("Failed to create directory!");
}
}
}
public Table CreateMDirectory(String nomDossier2) throws Exception {
//Pour creer plusieurs dossiers en se basant sur un Tableau
String ND2 = nomDossier2;
Table t2 = listDirectoryInFolder(ND2);
for (int i = 0; i <t2.rowCount() ; i++) { //
// System.out.println(t2.get(i, 0).toString()); //
File file = new File(ND2 + "\\" + "Selection " + t2.get(i, 0).toString());
if (file.exists()) {
// System.out.println("Directory exists already!"); //
} else {
file.mkdir();
// System.out.println("Directory is created!"); //
}
}
Table t3 = listDirectoryInFolder(ND2);
return t3;
}
public Table listDirectoryInFolder(String nomDossier) throws Exception {
String ND = nomDossier;
File file = new File(ND);
File[] listOfFiles = file.listFiles();
Table t = Table.create();
List<String> noma = new ArrayList<>();
List<String> patha = new ArrayList<>();
List<String> nomb = new ArrayList<>();
List<String> pathb = new ArrayList<>();
//Nombre de fichiers dans le dossier
System.out.println("Nombres de Files/Directory dans le dossier: "+listOfFiles.length);
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
//System.out.println("File Name: " + listOfFiles[i].getName());
noma.add(listOfFiles[i].getName());
//System.out.println("File Path: " + listOfFiles[i].getAbsolutePath());
patha.add(listOfFiles[i].getAbsolutePath()); }
else if (listOfFiles[i].isDirectory()) {
if (listOfFiles[i].getName().startsWith("Selection")){
//System.out.println("Directory Name: " + listOfFiles[i].getName());
nomb.add(listOfFiles[i].getName());
//System.out.println("Directory Path: " + listOfFiles[i].getAbsolutePath());
pathb.add(listOfFiles[i].getAbsolutePath());
}
else
{//System.out.println("Directory Name: " + listOfFiles[i].getName());
noma.add(listOfFiles[i].getName());
//System.out.println("Directory Path: " + listOfFiles[i].getAbsolutePath());
patha.add(listOfFiles[i].getAbsolutePath());}
}
}
String[] nom2 = new String[noma.size()];
String[] path2 = new String[patha.size()];
String[] nom3 = new String[noma.size()];
String[] path3 = new String[patha.size()];
nom2 = noma.toArray(nom2);
path2 = patha.toArray(path2);
nom3 = nomb.toArray(nom3);
path3 = pathb.toArray(path3);
StringColumn column0 = StringColumn.create("Nom fichier", nom2 );
StringColumn column1 = StringColumn.create("Path1", path2 );
StringColumn column2 = StringColumn.create("Nom dossier selection", nom3 );
StringColumn column3 = StringColumn.create("Path2", path3 );
t.addColumns(column0);
t.addColumns(column1);
t.addColumns(column2);
t.addColumns(column3);
//System.out.println(t);
t.write().csv("test.csv");
return t;
/*
t.clear();
noma.clear();
patha.clear();
column0.clear();
column1.clear();
nomb.clear();
pathb.clear();
column2.clear();
column3.clear();
*/
}
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)]));
}
}
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 = 13; i <t3.rowCount(); ) { //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 ia = 0; ia < nbrrestant;ia++ ) {
//System.out.println(Lepatha+"\\"+filesOrig[hazardNumbers.get(i)]);
System.out.println(Lepath2a+"\\"+filesOrig[hazardNumbers.get(i)]);
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);
Scanner myObj3 = new Scanner(System.in);
System.out.println("On augmente de combien la boucle?:");
int boucleavance = myObj3.nextInt();
i=i+boucleavance;
System.out.println("Bon, maintenant i est egal a: "+i);
//System.out.println(t3);
}
}
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.listDirectoryInFolder("G:\\Stock\\Ishibashi");
client.checkIfEnoughFilesForM("G:\\Stock\\Ishibashi");
//client.checkIfEnoughFilesfor1("G:\\Stock\\Ishibashi\\19 MEO","G:\\Stock\\Ishibashi\\Selection 19", 10);
}
} |
Partager