Write a program that consolidates the contents of a list of text
files into a single text file. The result of consolidation will
always be placed in the out folder. The list of files to be
consolidated are passed into the program from the command line.
Users must pass into the program in any order:
Files to be consolidated.
This can be a directory path or the file paths for two specific
files
[Optional arguments] Flag value, -for -d
The -f flag indicates to the program it should expect the file
paths for two text files. If more than two are given, the first two
valid text files will be used in the consolidation. The two files
will be consolidated in order of apperance (the contents of the
second file after the first). If less than two are given, then a
FileNotFoundError exception must be raised.
The -d flag indicates to the program it should expect a valid
directory path. If a valid directory path is given, then all files
in the directory will be consolidated in alphabetical order. If
none or an invalid path is given, a FileNotFoundError exception
must be raised.
If no flag value is received by the program, the program by
default expects a valid directory path and will behave in the same
way as if a -d flag was given. Invalid flag values are ignored by
the program. If more than one valid flag value is received, the
first valid flag is used by the program.
[Optional arguments] Destination file path
The destination file contains the resultant consolidated
contents. By default, the destination file is result.txt and will
always be placed in the folder out within the program's working
directory. If no file path is given, then result.txt must be
overwritten if it exists, or created otherwise.
If a destination file path is given in the form:
/home/out/<file_name>.txt, the program must check if the file
exists in the out folder. If it exists, a warning message must be
displayed to the terminal. In this warning the user must be
prompted to either enter w to overwrite the file, or a to append to
it. Otherwise, a new file is created to store the result of
consolidation.
Examples of program usage
These commands will consolidate all the text files inside
directory rhymes:
$ python3 program.py /home/rhymes $ python3 program.py -d
/home/rhymes
Write a program that consolidates the contents of a list of text files into a single text file. The result of consolidat
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Write a program that consolidates the contents of a list of text files into a single text file. The result of consolidat
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!