Question

CIS 265 Data Structures and Algorithms Assignment 7, 100 points Due: 10:15am, Thu, Mar. 19, 2020...

CIS 265 Data Structures and Algorithms Assignment 7, 100 points Due: 10:15am, Thu, Mar. 19, 2020 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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*
The program lists the contents of a directory specified by the user. The contents of subdirectories are also listed in this program up to any level of nesting. Indentation is used to show the level of nesting.

In the program,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

Add a comment
Know the answer?
Add Answer to:
CIS 265 Data Structures and Algorithms Assignment 7, 100 points Due: 10:15am, Thu, Mar. 19, 2020...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In java netbean8.1 or 8.2 please. The class name is Stock. It has 5 private attributes...

    In java netbean8.1 or 8.2 please. The class name is Stock. It has 5 private attributes (name, symbol, numberOfShares, currentPrice and boughtPrice)and one static private attribute (numberOfStocks). All attributes must be initialized (name and symbol to “No name/ symbol yet” and numberOfShares, currentPrice and boughtPrice to 0. Create two constructors, one with no arguments and the other with all the attributes. (However, remember to increase the numberOfStocks in both constructors. Write the necessary mutators and accessors (getters and setters) for...

  • Java program Program: Grade Stats In this program you will create a utility to calculate and...

    Java program Program: Grade Stats In this program you will create a utility to calculate and display various statistics about the grades of a class. In particular, you will read a CSV file (comma separated value) that stores the grades for a class, and then print out various statistics, either for the whole class, individual assignments, or individual students Things you will learn Robustly parsing simple text files Defining your own objects and using them in a program Handling multiple...

  • Your assignment is to write a grade book for a teacher. The teacher has a text file, which includ...

    Your assignment is to write a grade book for a teacher. The teacher has a text file, which includes student's names, and students test grades. There are four test scores for each student. Here is an example of such a file: Count: 5 Sally 78.0 84.0 79.0 86.0 Rachel 68.0 76.0 87.0 76.0 Melba 87.0 78.0 98.0 88.0 Grace 76.0 67.0 89.0 0.0 Lisa 68.0 76.0 65.0 87.0 The first line of the file will indicate the number of students...

  • C++ please Programming Assignment #6 Help Me Find The Secret Message Description: This assignment will require...

    C++ please Programming Assignment #6 Help Me Find The Secret Message Description: This assignment will require that you read in an encrypted message from a file, decode the message, and then output the message to a file. The encryption method being used on the file is called a shift cipher (Info Here). I will provide you with a sample encrypted message, the offset, and the decrypted message for testing. For this project I will provide you main.cpp, ShiftCipher.h, and ShiftCipher.cpp....

  • Assignment Overview In Part 1 of this assignment, you will write a main program and several...

    Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...

  • System Time Calculation Objectives of this Lab: The objective of this assignment is to get used...

    System Time Calculation Objectives of this Lab: The objective of this assignment is to get used to the system time information in Linux. You will do that by writing a small program (in either C, C++ or Java) that will access system time information available from the Linux /proc directory. How to proceed with the Program: 1. Information in the /proc/uptime is available just as though the file were a regular text file. You may open the file, read out...

  • In Java, Implement a class MyArray as defined below, to store an array of integers (int)....

    In Java, Implement a class MyArray as defined below, to store an array of integers (int). Many of its methods will be implemented using the principle of recursion. Users can create an object by default, in which case, the array should contain enough space to store 10 integer values. Obviously, the user can specify the size of the array s/he requires. Users may choose the third way of creating an object of type MyArray by making a copy of another...

  • Part 1 The purpose of this part of the assignment is to give you practice in...

    Part 1 The purpose of this part of the assignment is to give you practice in creating a class. You will develop a program that creates a class for a book. The main program will simply test this class. The class will have the following data members: A string for the name of the author A string for the book title A long integer for the ISBN The class will have the following member functions (details about each one are...

  • [15 marks] Suppose that students enrolled in one course are required to take four tests, and...

    [15 marks] Suppose that students enrolled in one course are required to take four tests, and each student’s final grade for this course is the average of his/her grades of these four tests. This question asks you to write a program that can be used to compute the lowest final grade, highest final grade and the average final grade. General Requirements: Use a5q1.c as the name of your C source code file. We will use the following command on bluenose...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT