Answers for "create a folder for multiple numbers in java"

0

create a folder for multiple numbers in java

fullPathFile.getParentFile().mkdirs();
Posted by: Guest on December-10-2020
0

create a folder for multiple numbers in java

public static void main(String[] args) {
    String dirPath = "D:\\temp\\";
    File dir = new File(dirPath);

    // Get Directory Listing
    File[] fileList = dir.listFiles();

    // Process each file
    for(int i=0; i < fileList.length; i++)
    {
        if(fileList[i].isFile()) {
            String fileName = fileList[i].getName();
            // Split at the file extension and the classgroup
            String[] fileParts = fileName.split("[_\\.]");
            System.out.println("One: " + fileParts[0] + ", Two: " + fileParts[1]);

            // Check directory exists
            File newDir = new File(dirPath + fileParts[0] + "\\" + fileParts[1]);
            if(!newDir.exists()) {
                // Create directory
                if(newDir.mkdirs()) {
                    System.out.println("Directory Created");
                }
            } 

            // Move file into directory
            if(fileList[i].renameTo(new File(dirPath + fileParts[0] + "\\" + fileParts[1] + "\\" + fileName))) {
                System.out.println("File Moved");
            }

        }
    }
}
Posted by: Guest on December-10-2020

Code answers related to "create a folder for multiple numbers in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language