Created
February 6, 2018 11:58
-
-
Save dineshr93/3a59fb44c0300ad282eaf1fb71ef35f8 to your computer and use it in GitHub Desktop.
get all Folder names and create the folder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.din.pack; | |
import java.io.BufferedReader; | |
import java.io.File; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class CreateFolders { | |
public static void main(String[] args) throws IOException { | |
BufferedReader abc = new BufferedReader(new FileReader(new File("D:/PT/Projects/current/1/bwb/paths/paths.txt"))); | |
List<String> lines = new ArrayList<String>(); | |
String line = null; | |
while((line = abc.readLine()) != null) { | |
lines.add(line); | |
} | |
abc.close(); | |
// If you want to convert to a String[] | |
String[] paths = lines.toArray(new String[]{}); | |
File f = null; | |
for (int j = 0; j < paths.length; j++) { | |
//System.out.println(paths[j]); | |
paths[j] =paths[j].replaceAll("V2016.2.1_RC1", "V2017.1.0_RC1"); //RC version change | |
paths[j] =paths[j].replaceFirst("2.1", "2017.1.0"); //top level folder | |
//System.out.println(paths[j]); | |
f = new File(paths[j]); | |
f.mkdirs(); | |
} | |
System.out.println("folders created"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.din.pack; | |
import java.io.File; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class GetAllFolderNames { | |
public static void main(String[] args) { | |
//Path parent = FileSystems.getDefault().getPath("D:/PT/Projects/current/1/bwb/2.1"); | |
List<File> l = getDirs(new File("D:/PT/Projects/current/1/bwb/2.1"), 2); //level 0 is parent , level 1, and so on | |
String[] paths = new String[l.size()]; | |
int i = 0; | |
for (File file : l) { | |
paths[i++] = file.getAbsolutePath(); | |
} | |
File f = null; | |
for (int j = 0; j < paths.length; j++) { | |
System.out.println(paths[j]); | |
paths[j] =paths[j].replaceAll("V2016.2.1_RC1", "V2017.1.0_RC2"); | |
paths[j] =paths[j].replaceFirst("2.1", "2017.1.0"); //top level folder | |
//System.out.println(paths[j]); | |
f = new File(paths[j]); | |
f.mkdirs(); | |
} | |
System.out.println("folders created"); | |
} | |
static List<File> getDirs(File parent, int level){ | |
List<File> dirs = new ArrayList<File>(); | |
for(File f: parent.listFiles()){ | |
if(f.isDirectory()) { | |
if (level==0) dirs.add(f); | |
else if (level > 0) dirs.addAll(getDirs(f,level-1)); | |
} | |
} | |
return dirs; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment