feat(gui): add script rename feature (PR #2374)

* feat(gui): add script rename feature (#2354)

* fix: resolve spotless check
This commit is contained in:
Yaroslav
2024-12-19 20:13:08 +02:00
committed by GitHub
parent ff95b9e999
commit fe41d6ed3d
13 changed files with 64 additions and 3 deletions
@@ -10,12 +10,15 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.FileVisitOption;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
@@ -267,6 +270,20 @@ public class FileUtils {
return Files.readString(textFile);
}
public static boolean renameFile(Path sourcePath, Path targetPath) {
try {
Files.move(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING);
return true;
} catch (NoSuchFileException e) {
LOG.error("File to rename not found {}", sourcePath, e);
} catch (FileAlreadyExistsException e) {
LOG.error("File with that name already exists {}", targetPath, e);
} catch (IOException e) {
LOG.error("Error renaming file {}", e.getMessage(), e);
}
return false;
}
@NotNull
public static File prepareFile(File file) {
File saveFile = cutFileName(file);