2023年7月19日17:12:22

master
zhangmeng 2023-07-19 17:12:28 +08:00
parent 58162c6928
commit 886c08ae1a
1 changed files with 33 additions and 24 deletions

View File

@ -1,6 +1,7 @@
package com.zhangmeng.tools.controller;
import com.zhangmeng.tools.utils.AlertUtils;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
@ -104,35 +105,43 @@ public class BatchUpdateFileNameController {
AtomicInteger fileCount = new AtomicInteger();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(System.lineSeparator());
try {
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
dir.toString().replace(replace, replace_after);
stringBuilder.append(dir);
stringBuilder.append(System.lineSeparator());
dirCount.incrementAndGet();
return super.preVisitDirectory(dir, attrs);
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
String name = file.toString().replace(replace,replace_after);
copy_del_file(file,Paths.get(name));
stringBuilder.append(name);
stringBuilder.append(System.lineSeparator());
fileCount.incrementAndGet();
return super.visitFile(file, attrs);
}
});
} catch (IOException e) {
e.printStackTrace();
}
new Thread(()->{
try {
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
dir.toString().replace(replace, replace_after);
stringBuilder.append(dir);
stringBuilder.append(System.lineSeparator());
dirCount.incrementAndGet();
return super.preVisitDirectory(dir, attrs);
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
String name = file.toString().replace(replace,replace_after);
copy_del_file(file,Paths.get(name));
stringBuilder.append(name);
stringBuilder.append(System.lineSeparator());
fileCount.incrementAndGet();
return super.visitFile(file, attrs);
}
});
} catch (IOException e) {
e.printStackTrace();
}
}).start();
stringBuilder.append("文件夹数:").append(dirCount);
stringBuilder.append(System.lineSeparator());
stringBuilder.append("文件数:").append(fileCount);
stringBuilder.append(System.lineSeparator());
result_show.setText(stringBuilder.toString());
Platform.runLater(()->{
result_show.setText(stringBuilder.toString());
});
}