From 023a537ffcaf0740ce5ae3d22af9b0cbb1dd770a Mon Sep 17 00:00:00 2001 From: manfromhuh Date: Fri, 6 Aug 2021 10:30:19 -0400 Subject: [PATCH] Initial commit --- build.xml | 73 +++++++++++++++++++++++++ src/picture_lister/Picture_Lister.java | 76 ++++++++++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 build.xml create mode 100644 src/picture_lister/Picture_Lister.java diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..21aad0f --- /dev/null +++ b/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project Picture_Lister. + + + diff --git a/src/picture_lister/Picture_Lister.java b/src/picture_lister/Picture_Lister.java new file mode 100644 index 0000000..2b315f8 --- /dev/null +++ b/src/picture_lister/Picture_Lister.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2021 manfromhuh + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +package picture_lister; + +import java.io.File; +import java.io.FilenameFilter; + +/** + * + * @author manfromhuh + */ +public class Picture_Lister { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + if (args.length == 0){//Check for input + System.out.println("No input.\nExiting..."); + System.exit(0); + } + String picture_dir = args[0]; + 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) { + + // get last index for '.' char + int lastIndex = name.lastIndexOf('.'); + + // get extension + String str = name.substring(lastIndex); + + // match path name extension + if(str.equals(".png") || str.equals(".jpg")) { + return true; + } + } + + return false; + } + }; + if (directoryPath.isDirectory()) { + System.out.println("Listing directory...\n"); + //List of all files and directories + 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]); + } + } else { + System.out.println("Not a directory.\nExiting..."); + System.exit(0); + } + } + +}