Advertisement
krismanohar

Untitled

Apr 19th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1.     protected static boolean performActionInFileFromStartToEndAndCloseAction(File file, ItemAction action,int startIndex, int endIndex, ItemAction close){
  2.        
  3.         try {
  4.             if(file.isDirectory()){
  5.                 int count = startIndex;
  6.                 File[] contents = file.listFiles();
  7.                
  8.                 if (endIndex == -1){
  9.                     //bit messy...but is an internal signal to process all items
  10.                     endIndex = contents.length-1;
  11.                 }
  12.                
  13.                 File item;
  14.                 for(int k = startIndex; k < contents.length && k <= endIndex; k++){
  15.                     item = contents[k];
  16.                     System.out.println("Start folder "+count +" "+item.getName());
  17.                     if(!action.doAction(item))
  18.                         return false;
  19.                     System.out.println("Completed folder "+count+ " ");
  20.                     count++;
  21.                 }
  22.                
  23.                 close.doAction(file);
  24.                
  25.             }
  26.         }catch(Exception e) {
  27.             System.err.println("Error!");
  28.             e.printStackTrace();
  29.             return false;
  30.         }  
  31.        
  32.         return true;
  33.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement