4e089d3774648d6f754f7a98eba2556f11b7e1a2
[mediacube.git] /
1 package hu.user.mediacube.integration.safedelete;
2
3 import lombok.extern.log4j.Log4j2;
4
5 import java.nio.file.Files;
6 import java.nio.file.Path;
7 import java.nio.file.Paths;
8
9 @Log4j2
10 public class FileOperations {
11
12     static public void silentDelete(Path path) {
13         try {
14             Files.delete(path);
15             log.info("File deleted: {}", path);
16         } catch (Exception e) {
17             log.catching(e);
18         }
19
20     }
21
22     static public void silentRename(Path source, String prefix) {
23         try {
24             String fileName = String.format("%s%s", prefix, source.getFileName().toString());
25             Path target = Paths.get(source.getParent().toAbsolutePath().toString(), fileName);
26             Files.move(source, target);
27             log.info("File renamed to: {}", target);
28         } catch (Exception e) {
29             log.catching(e);
30         }
31     }
32 }