public void process(String dirname) {

		FileWriter fw = null;

		try {
			File dir = new File(dirname);
			fw = new FileWriter(output);
			BufferedWriter bw = new BufferedWriter(fw);

			File[] fa = dir.listFiles(new EndsWithFilter(extension));

			for (File f : fa) {
				
				String name = f.getName();
				System.out.print(name + "\t"); 

				BufferedReader br = new BufferedReader(new FileReader(f));
				String ln = br.readLine();
				
				Iterator<Long> it = ids.iterator();
				
				while(it.hasNext()){
					if(ln.contains(Long.toString(it.next())+"=")){
						System.out.print("writing...\t");
						String fileName = f.getPath();
						int end = fileName.lastIndexOf(".");
						String substring = fileName.substring(0,end);
						File trjfile = new File(substring + ".trj");
						BufferedReader br2 = new BufferedReader(new FileReader(trjfile));
						String ln2 = br2.readLine();
						if(headerWrite){
							bw.write(ln2 + "\n");
							ln2 = br2.readLine();
							headerWrite=false;
						}
						while(ln2!=null){
							bw.write(ln2 + "\n");
							ln2 = br2.readLine();
						}
						br2.close();
						break; // We're already writing the file so don't need to check for other items in list
					}
				}
				System.out.println(" done.");
				br.close();
			}
			
			bw.flush();
			bw.close();

		} catch (IOException e) {
			System.out.println("Error accessing output file: " + output);
			e.printStackTrace();
		} finally {
			if (fw != null) {
				try {
					fw.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					System.out.println("ERROR: " + output + " could not be closed properly.");
					e.printStackTrace();
				}
			}
		}
		
		File ofile = new File(output);
		
		if(ofile.length()==0){
			System.out.println("\nWARNING: " + output + " length is 0\n");
		}

	}