
io.sealights.agents.plugin.upgrade.utils.FileAndFolderUtils Maven / Gradle / Ivy
package io.sealights.agents.plugin.upgrade.utils;
import io.sealights.agents.plugin.Utils.StringUtils;
import java.io.File;
import java.nio.file.Paths;
/**
* Created by shahar on 8/1/2016.
*/
public class FileAndFolderUtils {
public static File findFileInFolder(String folder, String fileName) {
if (StringUtils.isNullOrEmpty(folder) || StringUtils.isNullOrEmpty(fileName))
return null;
File folderFile = new File(folder);
File[] files = folderFile.listFiles();
if (files == null)
return null;
for (File f : files) {
if (f.getName().equals(fileName))
return f;
}
return null;
}
public static String join(String first , String... pathArgs){
return Paths.get(first, pathArgs).toString();
}
public static boolean verifyFolderExists(String folder) {
if (folder == null) {
throw new NullPointerException("Argument 'folder' can't be 'null'.");
}
File f = new File(folder);
if (f.isFile()) {
throw new IllegalArgumentException("'" + folder + "' should be path to a folder and not to a file.");
}
return f.isDirectory() || f.mkdirs();
}
public static boolean verifyFileExistsSafe(File file){
try {
if (file.getParentFile().exists() || file.getParentFile().mkdirs()) {
if (file.createNewFile())
return true;
}
}catch (Exception e){
//TODO: pass logger.
e.printStackTrace();
}
return false;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy