Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class directoryMethods
- {
- private String text;
- String freq[];
- private int keyWordCounter;
- File[] subDirFileArray;
- public void caller(){printTree("c:",0);}
- public void printTree(String path, int depth){
- for(int i = 0 ; i < depth; i++){System.out.println(" ");}
- System.out.println(path);
- if(path.isDirectory()){
- for(File sub:path.subFiles){
- printTree(sub);
- }
- }
- }
- public void DirectoryTree(){
- String startOfDirectory = "c:/";
- File dirFile = new File(startOfDirectory);
- File[] directory = dirFile.listFiles();
- if(directory != null){
- for(File x : directory){
- System.out.println(startOfDirectory+ x.getName());
- File subDirFile = new File(startOfDirectory+x.getName()+"/");
- subDirFileArray = subDirFile.listFiles();
- if(subDirFileArray != null){
- //System.out.println("\t"+"Accessible");
- /*for(File y : subDirFileArray){
- System.out.println("\t"+y.getName());
- }*/
- for(File y : subDirFileArray){
- System.out.println("\t/"+y.getName());
- File sSubDirFile = new File (startOfDirectory+x.getName()+"/"+y.getName()+"/");
- File[] sSubDirFileArray = sSubDirFile.listFiles();
- if(sSubDirFileArray != null){
- for(File z : sSubDirFileArray){
- System.out.println("\t\t"+z.getName());
- }
- }else{System.out.println("\t\tNot accesible");}
- }
- }else{
- System.out.println("\tNot accessible");
- }
- }
- }
- else{
- System.out.println("In C:/ Not accessible");
- }
- }
- public void AccesTest(){
- File file = new File("c:/Program Files/");
- File[] fileDir = file.listFiles();
- if(fileDir != null){
- for(File s : fileDir){
- System.out.println(s.getName());
- }
- }
- else
- {
- System.out.println("Acces Denied");
- }
- }
- /**Searches through all the text files in the given Folder for keywords.
- *
- */
- public void searchesAllTxtFilesInDirectoryForKeyWords(String whatKeyword) throws Exception
- {
- Scanner user_input = new Scanner(System.in);
- System.out.println("Type directory name: ");
- String user = user_input.next(); //User Input
- //System.out.println(directory[0]);
- String lKeyword = whatKeyword.toLowerCase();
- File dirFile = new File(user);
- String[] directory = dirFile.list();
- for(String s : directory){
- if(s.contains(".txt")){
- FileReader file = new FileReader("C:/Test/"+s+"/");
- BufferedReader reader = new BufferedReader(file);
- String text = "";
- String line = reader.readLine();
- while(line != null)
- {
- text += "\n" + line ;
- line = reader.readLine();
- }
- String words[] = text.split("[,.!?():;\\s]+");
- for(int i=0;i<words.length;i++){
- String word = words[i].toLowerCase();
- if(word.equals(lKeyword)){
- keyWordCounter += 1;
- }
- }
- }
- else
- {
- System.out.println("Can only read .txt files");
- }
- }
- System.out.println("The name '"+whatKeyword+"' was mentioned "+keyWordCounter+" times");
- }
- public void getAllTextFilesInDir(){
- }
- public void clearScreen()
- {
- System.out.print('\u000C');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement