-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReadMeGenerator.java
38 lines (31 loc) · 1.53 KB
/
ReadMeGenerator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.io.File;
public class ReadMeGenerator {
private static final String LEETCODE_PROBLEMS_URL = "https://leetcode.com/problems/";
private static final String SPACE_CODE = "%20";
private static final int NUMBER_IDX = 0;
private static final int NAME_IDX = 1;
public ReadMeGenerator() {
}
private String folderName = "";
public void printInConsoleReadMeFromFolder(String folderPath) {
File folder = new File(folderPath);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
String name = listOfFiles[i].getName();
String[] numberAndName = listOfFiles[i].getName().split("\\.");
System.out.println("|" + numberAndName[NUMBER_IDX] + "|"
+ "[" + numberAndName[NAME_IDX] + "]"
+ "(" + LEETCODE_PROBLEMS_URL + numberAndName[1].substring(1).toLowerCase().replaceAll(" ", "-") + "/description/"
+ ") | [Java](./" + folderName + name.replaceAll(" ", SPACE_CODE) + ")|Easy| ");
} else if (listOfFiles[i].isDirectory()) {
if (!".git".equals(listOfFiles[i].getName())) {
folderName = listOfFiles[i].getName() + "/";
System.out.println();
System.out.println("Directory " + folderName);
printInConsoleReadMeFromFolder(folderPath + "\\" + folderName);
}
}
}
}
}