public String createDirectories(String strDirPath){ File newDirectory; boolean isDirCreated = false; String newFilePath; int fileIdx=1; if (getFolderSize(new File(strDirPath)) <= 5242880){ newFilePath = strDirPath; newDirectory = new File(newFilePath); } else { newFilePath = strDirPath+"\\"+strDirPath.substring(strDirPath.lastIndexOf("\\"))+"_"+fileIdx;//rename the folder depending upon name of parentfoler_[1,2,3,...] newDirectory = new File(newFilePath); fileIdx++; } try { if(!newDirectory.exists()){ isDirCreated = newDirectory.mkdirs(); }else isDirCreated = true; } catch (SecurityException se){ JOptionPane.showMessageDialog(null, se, "AccessDenied Error: Class-FileFactory", 0); } if (isDirCreated) return newDirectory.getPath() ; else return null ; } public long getFolderSize(File directory) { long length = 0; for (File file : directory.listFiles()) { if (file.isFile()) length += file.length(); else length += getFolderSize(file); } return length; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)