A1: Command-Line Interaction
Find Search Utility
Build a command-line application that finds files. The output prints the absolute path of the found files.
Syntax: java FindFiles filetofind [-option argument1 argument2 ...]With this syntax, `filetofind` is the full name of the file with the extesion. `option' refers to one or more options that determine how renaming is handled. `arguments' are parameters that a particular option requires. Details are below.
Options are specific arguments provided to the program on the that determine how the command executes. Options always start with a dash ("-"), and typically require zero or more additional arguments to function.
The following options are supported:
-help :: print out a help page and exit the program. -reg :: find files using [filietofind] argument as a regular expression. -r :: execute the command recursively in subfiles. -dir [directory] :: find the files the specified directory [directory]. Default directory is the calling directory. -ext [ext1,ext2,...] :: find the files matching [filetofind] and with the given extensions [ext1, ext2,...]
Most options require one or more additional parameters to operate, which immediately follow the option on the command-line. Parameters cannot start with a dash ("-"), since that symbol is used to designate options. Parameters consist of a string.
In the case of options that support multiple parameters (described below), they should be separated by a comma. e.g. `java FindFiles img -ext jpg,png'
The `-help' `-reg` and `-r` option does not require additional parameters.
The `-ext' option supports one or more parameters. If more than one parameter is provided, they should be separated by a comma(e.g. `-ext jpg,png,tiff').
The `-reg` option has no argument and indicates that the given [filetofind] argument should be treated as a regular expression, not a filename (e.g. FindFile .*movie.*\.txt -reg finds all text files that have movie in its name).
The `-r` option has no argument and indicates that the search will be also done in the sub-directories
The `-dir' option supports one argument that indicates in which directory the search should be done.
Processing Options & Parameters
Specifying the `-help’ option will cause the program to ignore all other options, display the help text, and exit.
The user is expected to provide a minimum number of options required to execute (filetofind should always be set. Or at least the .* with the -reg option). If the user doesn't provide the minimum number of options, then you should display the help text and exit.
If the user supplies invalid arguments or options, you should report an appropriate error and exit e.g. "'-flyingcows' is an invalid option. Please supply valid options from the following list..."
If the options are valid but the there are missing or invalid parameters, you should provide a detailed error on how to address it and exit. e.g. `java FindFiles .*test.* -reg -ext ' might report "Invalid option: ext requires arguments to be specified."'
If there is an more than one error in the given command, you should just print the first error, then print the help and exit.
When performing a file search, you should echo the operations as you perform them, so that the user has immediate feedback (e.g. "looking for files `f1' in `myDirectory`). Ideally, this would be a progress bar or something similar as the operation is performed; for this assignment, echoing the operation that was performed is sufficient.
java FindFiles test.txt
java FindFiles test.txt -r -dir ./myDirectory ⇒ find the files named 'test.text' in myDirectory folder and all its sub folders.
java FindFiles .*bla.* -reg ⇒ find all the files that have bla in their name.
java FindFiles .* -ext txt,java -reg ⇒ find all the files with txt or java extensions
java FindFiles -ext txt,java // no filename to find provided
java FindFiles test.text -dir // no directory argument provided
The `-help' option should display all of the options and their required arguments. The format should resemble this:
Usage java FindFiles filetofind [-option arg] -help :: print out a help page and exit the program. -reg :: find files using [filietofind] argument as a regular expression. -r :: execute the command recursively in subfiles. -dir [directory] :: find the files the specified directory [directory]. Default directory is the calling directory. -ext [ext1,ext2,...] :: find the files matching [filetofind] and with the given extensions [ext1, ext2,...]
- You must use Java 11 and IntelliJ 2019.3 or later. You are required to submit the source code and project files.
- You may use classes from the JDK, and samples provided in the public repo. You cannot use any other source code without permission from the instructor.
- Your main class should be named `FindFIles' and reside, with a main() method, in a file named `FindFiles.java'.
Your directory structure for your assignment submission should look something like this.
a1/ ├── a1.iml ├── out ├── readme.md └── src └── FindFiles.java
Your submission needs to include:
- All source code, resources required to build your project.
- An IntelliJ project compiles everything using the specified JDK.
- A `readme.md' file with any details required to help the TA grade your assignment.
Your `readme.md' file needs to include, at a minimum, your name, student number, the version of Java that you used (from `java -version'), and your operating system. If the TA needs to know anything else to run your assignment (e.g. undocumented hotkeys), include them in this file. For example:
Jeff Avery 12345678 j2avery openjdk version "11.0.2" 2019-04-16 macOS 10.14.6 (MacBook Pro 2017)
Your submission will be assessed roughly as follows:
- Complete submission including project file and `readme'. Code compiles and runs.
- Correctly parse and identify options and arguments.
- Provide feeback on incorrect options and arguments.
- Combine multiple options in one command.
- Find files correctly using the operations above.
1.0 Apr 25, 2020. Initial draft.