Making NufxScan a bit more useful. Include list of directories on the

command-line. Will recurse into subdirectories as well.
This commit is contained in:
Rob Greene 2018-03-10 22:09:27 -06:00
parent e178f124ed
commit 8f4ca7fb9f

View File

@ -1,12 +1,10 @@
package com.webcodepro.shrinkit; package com.webcodepro.shrinkit;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FilenameFilter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
/** /**
* Scan through the directories in NufxScan.txt, looking for * Scan through the directories in NufxScan.txt, looking for
@ -23,26 +21,36 @@ public class NufxScan {
private static long sizeOfSmallestCompressedFile; private static long sizeOfSmallestCompressedFile;
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
BufferedReader r = new BufferedReader(new InputStreamReader(NufxScan.class.getResourceAsStream("NufxScan.txt"))); for (String dir : args) {
String line = r.readLine(); scanDirectory(dir);
while (line != null) {
scanDirectory(line);
line = r.readLine();
} }
} }
private static void scanDirectory(String dirName) throws IOException { private static void scanDirectory(String dirName) throws IOException {
File dir = new File(dirName); File dir = new File(dirName);
if (!dir.isDirectory()) { scanDirectory(dir);
throw new IllegalArgumentException("'" + dirName + "' is not a directory"); }
private static void scanDirectory(File directory) throws IOException {
System.out.printf("Scanning '%s'...\n", directory.toString());
if (!directory.isDirectory()) {
throw new IllegalArgumentException("'" + directory.toString() + "' is not a directory");
} }
File[] files = dir.listFiles(new FilenameFilter() { File[] files = directory.listFiles(new FileFilter() {
public boolean accept(File dir, String name) { public boolean accept(File file) {
return name.toLowerCase().endsWith(".shk") || name.toLowerCase().endsWith(".sdk"); boolean isSHK = file.getName().toLowerCase().endsWith(".shk");
boolean isSDK = file.getName().toLowerCase().endsWith(".sdk");
boolean isDirectory = file.isDirectory();
boolean keep = isSHK || isSDK || isDirectory;
return keep;
} }
}); });
for (File file : files) { for (File file : files) {
display(file); if (file.isDirectory()) {
scanDirectory(file);
} else {
displayArchive(file);
}
} }
if (sizeOfSmallestCompressedFile != 0) { if (sizeOfSmallestCompressedFile != 0) {
System.out.printf("\n\nSmallest compressed file:\n"); System.out.printf("\n\nSmallest compressed file:\n");
@ -52,7 +60,7 @@ public class NufxScan {
} }
} }
private static void display(File archive) throws IOException { private static void displayArchive(File archive) throws IOException {
System.out.printf("Details for %s\n\n", archive.getAbsoluteFile()); System.out.printf("Details for %s\n\n", archive.getAbsoluteFile());
try (InputStream is = new FileInputStream(archive)) { try (InputStream is = new FileInputStream(archive)) {
NuFileArchive a = new NuFileArchive(is); NuFileArchive a = new NuFileArchive(is);