In: Computer Science
I. General Description In this assignment, you will create a Java program to search recursively for a file in a directory.
• The program must take two command line parameters. First parameter is the folder to search for. The second parameter is the filename to look for, which may only be a partial name.
• If incorrect number of parameters are given, your program should print an error message and show the correct format.
• Your program must search recursively in the given directory for the files whose name contains the given filename. Once a match is found, your program should print the full path of the file, followed by a newline.
• A sample run of the program may look like this:
//The following command line example searches any file with “Assignment” in its name
%java FuAssign7.FuAssignment7
C:\CIS 265 Assignment
C:\CIS 265\AS 2\FuAssignment2.class
C:\CIS 265\AS 2\FuAssignment2.java
C:\CIS 265\AS 3\FuCIS265\FuAssignment3.class
C:\CIS 265\AS 3\FuCIS265\FuAssignment3.java
C:\CIS 265\AS 4\FuAssign4\FuAssignment4.class
C:\CIS 265\AS 4\FuAssign4\FuAssignment4.java
C:\CIS 265\AS 4\FuAssignment4.gpj
II. Submission
This is an individual assignment. Each student needs to submit the source code files of the Java program on Blackboard.
1. Put all you Java files in a folder. Please name the folder after your package name, for example, FuAssign7. Compress the folder into a .zip file and submit the .zip file.
2. You need to only submit the source code, i.e., the Java files.
3. You may submit multiple time. Your most recent submission before the deadline will be graded.
III. Grading
1. A program that does not run will receive 0 point.
2. There is a 10-20 points deduction for each major error, e.g., missing a file in the output.
3. There is a 1-9 points deduction for each minor error, e.g., a spelling error in printed message.
4. A program that does not follow the guidelines will lose 1-10 points.
5. Any type of cheating is not tolerated. You may be asked to explain your program in person.
IV. Bonus features (optional)
If you implement any bonus feature in your program, please put a comment in your Blackboard submission and in your main Java file.
1. (5 points) Your program prints file size and date of creation for each file, e.g.,
C:\CIS 265\AS 2\FuAssignment2.class Sat Jan 18 15:47:53 EST 2020 1870
/* This program lists the contents of a directory specified by the user. The contents of subdirectories are also listed, up to any level of nesting. Indentation is used to show the level of nesting. The user is asked to type in a directory name. If the name entered by the user is not a directory, a message is printed and the program ends. */ import java.io.*; public class RecursiveDirectoryList { public static void main(String[] args) { String directoryName; // Directory name entered by the user. File directory; // File object referring to the directory. TextIO.put("Enter a directory name: "); directoryName = TextIO.getln().trim(); directory = new File(directoryName); if (directory.isDirectory() == false) { // Program needs a directory name. Print an error message. if (directory.exists() == false) TextIO.putln("There is no such directory!"); else TextIO.putln("That file is not a directory."); } else { // List the contents of directory, with no indentation // at the top level. listContents( directory, "" ); } } // end main() static void listContents(File dir, String indent) { // A recursive subroutine that lists the contents of // the directory dir, including the contents of its // subdirectories to any level of nesting. It is assumed // that dir is in fact a directory. The indent parameter // is a string of blanks that is prepended to each item in // the listing. It grows in length with each increase in // the level of directory nesting. String[] files; // List of names of files in the directory. TextIO.putln(indent + "Directory \"" + dir.getName() + "\":"); indent += " "; // Increase the indentation for listing the contents. files = dir.list(); for (int i = 0; i < files.length; i++) { // If the file is a directory, list its contents // recursively. Otherwise, just print its name. File f = new File(dir, files[i]); if (f.isDirectory()) listContents(f, indent); else TextIO.putln(indent + files[i]); } } // end listContents() } // end class RecursiveDirectoryList