|
|
|
@ -26,6 +26,7 @@ import java.util.function.Function;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
|
|
|
|
@ -203,36 +204,39 @@ public class CmmnUtil {
|
|
|
|
|
* @return 삭제된 폴더수
|
|
|
|
|
*/
|
|
|
|
|
public static void removeDuplicateFileName(String root) {
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
List<Path> fileList = Files.walk(Paths.get(root)).filter(Files::isRegularFile).toList();
|
|
|
|
|
|
|
|
|
|
Map<String, List<Path>> byFileName = fileList.stream().collect(Collectors.groupingBy(item -> item.toFile().getName()));
|
|
|
|
|
|
|
|
|
|
Iterator<String> keys = byFileName.keySet().iterator();
|
|
|
|
|
|
|
|
|
|
while( keys.hasNext() ){
|
|
|
|
|
String key = keys.next();
|
|
|
|
|
List<Path> sameNameFileList = byFileName.get(key);
|
|
|
|
|
if(sameNameFileList.size() < 2) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Path latest = sameNameFileList.stream()
|
|
|
|
|
.max(Comparator.comparing(item -> item.toFile().lastModified()))
|
|
|
|
|
.orElseThrow();
|
|
|
|
|
|
|
|
|
|
for(Path sameNameFile : sameNameFileList) {
|
|
|
|
|
if(!sameNameFile.equals(latest)) {
|
|
|
|
|
sameNameFile.toFile().delete();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<Path> fileList = null;
|
|
|
|
|
try (Stream<Path> pathStream = Files.walk(Paths.get(root))){
|
|
|
|
|
|
|
|
|
|
fileList = pathStream.filter(Files::isRegularFile).toList();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(fileList != null && !fileList.isEmpty()) {
|
|
|
|
|
Map<String, List<Path>> byFileName = fileList.stream().collect(Collectors.groupingBy(item -> item.toFile().getName()));
|
|
|
|
|
|
|
|
|
|
Iterator<String> keys = byFileName.keySet().iterator();
|
|
|
|
|
|
|
|
|
|
while( keys.hasNext() ){
|
|
|
|
|
String key = keys.next();
|
|
|
|
|
List<Path> sameNameFileList = byFileName.get(key);
|
|
|
|
|
if(sameNameFileList.size() < 2) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Path latest = sameNameFileList.stream()
|
|
|
|
|
.max(Comparator.comparing(item -> item.toFile().lastModified()))
|
|
|
|
|
.orElseThrow();
|
|
|
|
|
|
|
|
|
|
for(Path sameNameFile : sameNameFileList) {
|
|
|
|
|
if(!sameNameFile.equals(latest)) {
|
|
|
|
|
if(!sameNameFile.toFile().delete()) {
|
|
|
|
|
throw new RuntimeException("[F]파일 삭제 오류");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|