Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

create a folder for multiple numbers in java

public static void main(String[] args) {
    String dirPath = "D:	emp";
    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");
            }

        }
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #create #folder #multiple #numbers #java
ADD COMMENT
Topic
Name
9+7 =