Skip to content

Instantly share code, notes, and snippets.

@phl0w
Created July 31, 2012 17:06
Show Gist options
  • Select an option

  • Save phl0w/3218556 to your computer and use it in GitHub Desktop.

Select an option

Save phl0w/3218556 to your computer and use it in GitHub Desktop.
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
public class MergeV2 {
private static final Logger log = Logger.getLogger(MergeV2.class.getName());
private static final File ROOT_FOLDER = new File(System.getProperty("user.home") + (System.getProperty("os.name").contains("Windows") ? "/AppData/Roaming/X-Chat 2/xchatlogs" : "/.xchat2/xchatlogs"));
private static final HashMap<String, File[]> files = new HashMap<String, File[]>();
public static void main(String... args) {
if (ROOT_FOLDER.exists()) {
for (final File f : ROOT_FOLDER.listFiles()) {
if (f.isDirectory() && f.getName().contains("System")) { //mandatory check
for (final File sub : f.listFiles()) {
String channelName = sub.getName().split("#")[1].replaceAll(".log", "");
log.info("Channel found: #" + channelName);
if (files.containsKey(channelName)) {
final ArrayList<File> temp = new ArrayList<File>();
for (File t : files.get(channelName)) {
temp.add(t);
}
temp.add(sub);
files.put(channelName, (File[]) temp.toArray());
} else {
files.put(channelName, new File[]{sub});
}
}
}
}
} else {
log.info("No log folder detected.");
}
for (Map.Entry<String, File[]> es : files.entrySet()) {
StringBuilder sb = new StringBuilder();
for (File f : es.getValue()) {
sb.append(f.getName() + " ");
}
log.info("Channel: #" + es.getKey() + ", files: " + sb.toString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment