19 package org.sleuthkit.autopsy.coreutils;
22 import java.io.IOException;
23 import java.util.logging.Level;
24 import org.openide.filesystems.FileObject;
25 import java.nio.file.Files;
26 import java.nio.file.Path;
48 if (dirPath.isDirectory() ==
false || dirPath.exists() ==
false) {
49 logger.log(Level.WARNING,
"deleteDir passed in a non-directory: {0}", dirPath.getPath());
53 File[] files = dirPath.listFiles();
54 boolean hadErrors =
false;
56 for (File file : files) {
57 if (file.isDirectory()) {
63 if (file.delete() ==
false) {
64 logger.log(Level.WARNING,
"Failed to delete file {0}", file.getPath());
70 if (dirPath.delete() ==
false) {
71 logger.log(Level.WARNING,
"Failed to delete the empty directory at {0}", dirPath.getPath());
88 boolean sucess =
true;
92 logger.log(Level.WARNING,
"Failed to delete file {0}", path.getPath());
116 public static String
copyFile(String source, String destFolder, String newName, String ext,
boolean overwrite)
119 final String destFileName = destFolder + File.separator + newName + ext;
120 final File destFile =
new File(destFileName);
121 if (destFile.exists()) {
129 final FileObject sourceFileObj =
org.openide.filesystems.FileUtil.createData(
new File(source));
130 final FileObject destFolderObj =
org.openide.filesystems.FileUtil.createData(
new File(destFolder));
133 FileObject created =
org.openide.filesystems.FileUtil.copyFile(sourceFileObj, destFolderObj, newName, ext.substring(1));
135 return created.getPath();
150 public static String
copyFolder(String source, String path, String folderName)
throws IOException {
151 String destFolder = path + File.separator + folderName;
152 org.openide.filesystems.FileUtil.createFolder(
new File(destFolder));
154 final FileObject sourceFileObj =
org.openide.filesystems.FileUtil.createData(
new File(source));
155 final FileObject destFolderObj =
org.openide.filesystems.FileUtil.createData(
new File(destFolder));
157 FileObject created =
org.openide.filesystems.FileUtil.copyFile(sourceFileObj, destFolderObj, sourceFileObj.getName(), sourceFileObj.getExt());
159 return created.getPath();
173 return fileName.replaceAll(
"[\\p{Cntrl}/:\"*?<>|]+",
"_").trim();
187 p = Files.createTempFile(dirPath, TEMP_FILE_NAME, TEMP_FILE_EXT);
188 return (p.toFile().canRead() && p.toFile().canWrite());
189 }
catch (IOException ex) {
195 }
catch (Exception ignored) {
static final String TEMP_FILE_NAME
static String copyFile(String source, String destFolder, String newName, String ext, boolean overwrite)
static final Logger logger
static boolean deleteFileDir(File path)
static boolean hasReadWriteAccess(Path dirPath)
static final String TEMP_FILE_EXT
static String copyFolder(String source, String path, String folderName)
static String escapeFileName(String fileName)
synchronized static Logger getLogger(String name)
static boolean deleteDir(File dirPath)