annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/opt/bbmap-39.01-1/current/fileIO/FindFiles.java @ 68:5028fdace37b

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 16:23:26 -0400
parents
children
rev   line source
jpayne@68 1 package fileIO;
jpayne@68 2
jpayne@68 3 import java.io.File;
jpayne@68 4 import java.util.ArrayList;
jpayne@68 5
jpayne@68 6
jpayne@68 7 public class FindFiles {
jpayne@68 8
jpayne@68 9
jpayne@68 10 public static void main(String[] args){
jpayne@68 11
jpayne@68 12 String root=args[0];
jpayne@68 13 // if(root.equals(".")){root=null;}
jpayne@68 14 String prefix=args[1];
jpayne@68 15 String suffix=(args[2].equals("null") ? null : args[2]);
jpayne@68 16 String middle=null;
jpayne@68 17
jpayne@68 18 if(args.length>3){
jpayne@68 19 middle=(args[3].equals("null") ? null : args[3]);
jpayne@68 20 }
jpayne@68 21
jpayne@68 22 boolean NEWLINE=true;
jpayne@68 23 boolean BOTH=true;
jpayne@68 24
jpayne@68 25 ArrayList<String> results=findFiles(root, prefix, suffix, middle);
jpayne@68 26 for(String s : results){
jpayne@68 27 if(NEWLINE){
jpayne@68 28 System.out.println(s);
jpayne@68 29 }else{
jpayne@68 30 System.out.print(s+" ");
jpayne@68 31 }
jpayne@68 32 }
jpayne@68 33
jpayne@68 34
jpayne@68 35 if(BOTH){
jpayne@68 36 System.out.println();
jpayne@68 37 NEWLINE=!NEWLINE;
jpayne@68 38 for(String s : results){
jpayne@68 39 if(NEWLINE){
jpayne@68 40 System.out.println(s);
jpayne@68 41 }else{
jpayne@68 42 System.out.print(s+" ");
jpayne@68 43 }
jpayne@68 44 }
jpayne@68 45 }
jpayne@68 46 }
jpayne@68 47
jpayne@68 48
jpayne@68 49 public FindFiles(String pre, String suf, String mid){
jpayne@68 50 assert(!"*".equals(pre)) : "Use # instead of *, which has problems from the command line";
jpayne@68 51 assert(!"*".equals(suf)) : "Use # instead of *, which has problems from the command line";
jpayne@68 52 prefix=((pre==null || pre.equals("*") || pre.equals("#")) ? null : pre.toLowerCase());
jpayne@68 53 suffix=((suf==null || suf.equals("*") || suf.equals("#")) ? null : suf.toLowerCase());
jpayne@68 54 middle=((mid==null || mid.equals("*") || mid.equals("#")) ? null : mid.toLowerCase());
jpayne@68 55 }
jpayne@68 56
jpayne@68 57 public static ArrayList<String> findFiles(String root, String prefix, String suffix){
jpayne@68 58 return findFiles(root, prefix, suffix, null);
jpayne@68 59 }
jpayne@68 60
jpayne@68 61 public static ArrayList<String> findFiles(String root, String prefix, String suffix, String mid){
jpayne@68 62 FindFiles ff=new FindFiles(prefix, suffix, mid);
jpayne@68 63 return ff.findFiles(root);
jpayne@68 64 }
jpayne@68 65
jpayne@68 66 public ArrayList<String> findFiles(String path){
jpayne@68 67 findFiles(new File(path==null ? "." : path));
jpayne@68 68 return results;
jpayne@68 69 }
jpayne@68 70
jpayne@68 71 public ArrayList<String> findFiles(File path){
jpayne@68 72
jpayne@68 73 if(path.isDirectory()){
jpayne@68 74 File[] array=path.listFiles();
jpayne@68 75 if(array==null){System.err.println("null contents for "+path.getAbsolutePath());}
jpayne@68 76 else{for(File f : array){findFiles(f);}}
jpayne@68 77 }else{
jpayne@68 78 consider(path);
jpayne@68 79 }
jpayne@68 80 return results;
jpayne@68 81 }
jpayne@68 82
jpayne@68 83 public void consider(File in){
jpayne@68 84 // System.out.println("Considering "+in.getAbsolutePath()+" versus '"+prefix+"' '"+suffix+"'");
jpayne@68 85 if(!in.exists()){return;}
jpayne@68 86 assert(in.exists()) : in;
jpayne@68 87 assert(in.isFile());
jpayne@68 88 String abs=in.getAbsolutePath();
jpayne@68 89 // System.out.println("Considering "+abs);
jpayne@68 90 String abs2=abs.toLowerCase();
jpayne@68 91 int slashLoc=abs2.lastIndexOf(slash);
jpayne@68 92 if(slashLoc>-1){
jpayne@68 93 abs2=abs2.substring(slashLoc+1);
jpayne@68 94 }
jpayne@68 95 // System.out.println("a");
jpayne@68 96 if(prefix!=null && !abs2.startsWith(prefix)){return;}
jpayne@68 97 // System.out.println("b");
jpayne@68 98 if(suffix!=null && !abs2.endsWith(suffix)){return;}
jpayne@68 99 // System.out.println("c");
jpayne@68 100
jpayne@68 101 if(middle!=null && !abs2.contains(middle)){return;}
jpayne@68 102
jpayne@68 103 results.add(abs);
jpayne@68 104 }
jpayne@68 105
jpayne@68 106
jpayne@68 107 public ArrayList<String> results=new ArrayList<String>();
jpayne@68 108 public String prefix;
jpayne@68 109 public String suffix;
jpayne@68 110 public String middle;
jpayne@68 111 public static final char slash=System.getProperty("file.separator").charAt(0);
jpayne@68 112
jpayne@68 113 }