Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.Scanner;
- public class Launcher {
- static File dir = new File(System.getProperty("user.dir") + "\\Files\\");
- static File log = new File(System.getProperty("user.dir")+"\\structure.txt");
- static int lines = 0;
- static int spc_count = -1;
- static void Process(File aFile) throws FileNotFoundException{
- spc_count += 2;
- String spcs = "";
- for(int i = 0; i < spc_count; i++){
- spcs += " ";
- }
- if(aFile.isFile()){
- echo(spcs + "[FILE] " + aFile.getName());
- countLines(aFile);
- }else if(aFile.isDirectory()){
- echo(spcs + "[DIR] " + aFile.getName());
- File[] listOfFiles = aFile.listFiles();
- if(listOfFiles != null){
- for(int i = 0; i < listOfFiles.length; i++){
- Process(listOfFiles[i]);
- }
- }else{
- echo(spcs + " [ACCESS DENIED]");
- }
- }
- spc_count -= 2;
- }
- public static void main(String[] args) throws FileNotFoundException{
- Process(dir);
- echo("Total lines: " + lines);
- }
- private static void countLines(File file) throws FileNotFoundException{
- Scanner scanner = new Scanner(file);
- while (scanner.hasNextLine()){
- @SuppressWarnings ("unused")
- String line = scanner.nextLine();
- lines++;
- }
- }
- public static void echo(String str){
- System.out.println(str);
- addToLog(str);
- }
- public static void addToLog(String loge){
- try{
- BufferedWriter out = new BufferedWriter(new FileWriter(log, true));
- out.write(loge+"\r\n");
- out.close();
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment