Code cleanup
I have cleaned up a lot of the code.
This commit is contained in:
parent
dc53ab5e12
commit
7bec57b557
@ -21,6 +21,7 @@ import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -38,8 +39,8 @@ public class Picture_Lister {
|
||||
}
|
||||
String picture_dir = args[0];
|
||||
List<String> file_format = new ArrayList<>();
|
||||
if (args.length > 1){//Check if any argumets other than the path have been passed.
|
||||
for(int i = 1; i < args.length; i++){
|
||||
if (args.length > 1){//Check if any arguments other than the path have been passed.
|
||||
for(int i = 1; i < args.length; i++){//Ignore IDE warning about manual sort. See end of file.
|
||||
file_format.add(args[i]);
|
||||
}
|
||||
} else {//The default formats to look for if none are given.
|
||||
@ -49,36 +50,32 @@ public class Picture_Lister {
|
||||
System.out.println(picture_dir);
|
||||
//Creating a File object for directory
|
||||
File directoryPath = new File(picture_dir);
|
||||
FilenameFilter picture_filter = new FilenameFilter() {
|
||||
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
if(name.lastIndexOf('.')>0) {
|
||||
String[] include = file_format.toArray(new String[file_format.size()]);
|
||||
// get last index for '.' char
|
||||
int lastIndex = name.lastIndexOf('.');
|
||||
|
||||
// get extension
|
||||
String str = name.substring(lastIndex);
|
||||
|
||||
// match path name extension
|
||||
for (String place_holder : include) {
|
||||
if (str.equalsIgnoreCase(place_holder)) {
|
||||
return true;
|
||||
}
|
||||
FilenameFilter picture_filter = (dir, name) -> {
|
||||
if(name.lastIndexOf('.')>0) {
|
||||
String[] include = file_format.toArray(new String[0]);
|
||||
// get last index for '.' char
|
||||
int lastIndex = name.lastIndexOf('.');
|
||||
|
||||
// get extension
|
||||
String str = name.substring(lastIndex);
|
||||
|
||||
// match path name extension
|
||||
for (String place_holder : include) {
|
||||
if (str.equalsIgnoreCase(place_holder)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
if (directoryPath.isDirectory()) {
|
||||
System.out.println("Listing directory...\n");
|
||||
//List of all files and directories
|
||||
File contents[] = directoryPath.listFiles(picture_filter);
|
||||
File[] contents = directoryPath.listFiles(picture_filter);
|
||||
System.out.println("List of files and directories in the specified directory:");
|
||||
for (int i = 0; i < contents.length; i++) {
|
||||
System.out.println(contents[i]);
|
||||
for (File content : Objects.requireNonNull(contents)) {
|
||||
System.out.println(content);
|
||||
}
|
||||
} else {
|
||||
System.out.println("Not a directory.\nExiting...");
|
||||
@ -87,3 +84,9 @@ public class Picture_Lister {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
Some editors will complain about this being a manual Array to
|
||||
Collection sort. This is done because the first member of the array
|
||||
Doesn't belong. The first member of the array will always be a Path.
|
||||
*/
|
Loading…
x
Reference in New Issue
Block a user