Your program will take input from the console in the following format. It should not prompt...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Your program will take input from the console in the following format. It should not prompt the user in any way. The intent here is not to write a user-friendly user interface; what you're actually doing is building a program that we can test automatically, so it's vital that your program reads inputs and writes outputs precisely as specified below. ● First, the program reads a line of input that specifies which files are eligible to be found. That can be specified in one of two ways: • The letter D, followed by a space, followed (on the rest of the line) by the path to a directory. In this case, all of the files in that directory will be under consideration, but no subdirectories (and no files in those subdirectories) will be. (You can think of the letter D here as standing for "directory.") o The letter R, followed by a space, followed (on the rest of the line) by the path to a directory. In this case, all of the files in that directory will be under consideration, along with all of the files in its subdirectories, all of the files in their subdirectories, and so on. (You can think of the letter R here as standing for "recursive.") o If this line of input does not follow this format, or if the directory specified does not exist, print the word ERROR on a line by itself and repeat reading this line of input; continue until the input is valid. Next, the program prints the paths to every file that is under consideration. Each path is printed on its own line, with no whitespace preceding or following it, and with every line ending in a newline. Note, also, that the order in which the files' paths are printed is relevant; you must print them in the following order: o First, the paths to all of the files in the directory are printed. These are printed in lexicographical order of the file's names. (More on lexicographical order a bit later, but note that this is the default way that strings are sorted.) • Next, if the files in subdirectories are being considered, the files in each of the subdirectories are printed according to the same ordering rules here, with all of the files in one subdirectory printed before any of the others, and with the subdirectories printed in lexicographical order of their names. ● Now that the program has displayed the paths of every file under consideration, it's time to narrow our search. The program now reads a line of input that describes the search characteristics that will be used to decide whether files are "interesting" and should have action taken on them. There are five different characteristics, and this line of input chooses one of them. . If this line of input is the letter A alone on a line, all of the files found in the previous step are considered interesting. O If this line of input begins with the letter N, the search will be for files whose names exactly match a particular name. The N will be followed by a space; after the space, the rest of the line will indicate the name of the files to be searched for. Note that filenames include extensions, so a search for boo would not find a file named boo.doc. ■ If this line of input begins with the letter E, the search will be for files whose names have a particular extension. The E will be followed by a space; after the space, the rest of the line will indicate the desired extension. For example, if the desired extension is py, all files whose names end in .py will be considered interesting. The desired extension may be specified with or without a dot preceding it (e.g., E .py or E py would mean the same thing in the input), and your search should behave the same either way. ■ Note, also, that there is a difference between what you might call a name ending and an extension. In our program, if the search is looking for files with the extension oc, a file named iliveinthe.oc would be found, but a file named invoice.doc would not. o If this line of input begins with the letter T, the search will be for text files that contain the given text. The T will be followed by a space; after the space, the rest of the line will indicate the text that the file should contain in order to be considered interesting. ■ For example, if this line of input reads T while True, any text file containing the text "while True" would be considered interesting. ▪ One thing to note is that not all files are text files, but that you can't determine that by their name or their extension. Any file that can be opened and read as a text file is considered a text file for our purposes here, regardless of its name. Any file that cannot be opened and read as a text file should be skipped (i.e., it is not considered interesting). o If this line of input begins with the character <, the search will be for files whose size, measured in bytes, is less than a specified threshold. The < will be followed by a space; after the space, the rest of the line will be a non-negative integer value specifying the size threshold. . For example, the input < 65536 means that files whose sizes are no more than 65,535 bytes (i.e., less than 65,536 bytes) will be considered interesting. If this line of input begins with the character >, the search will be for files whose size, measured in bytes, is greater than a specified threshold. The > will be followed by a space; after the space, the rest of the line will be a non-negative integer value specifying the size threshold. For example, the input > 2097151 means that files whose sizes are at least 2,097,152 bytes (i.e., greater than 2,097,151 bytes) will be considered interesting. If this line of input does not match one of the formats described above, print the word ERROR on a line by itself and repeat reading a line of input; continue until the input is valid. Note that it is not an error to specify a search characteristic that matches no files; it's only an error if this line of input is structurally invalid (i.e., it does not match one of the formats above). • ● ● Next, the program prints the paths to every file that is considered interesting, based on the search characteristic. Each path is printed on its own line, with no whitespace preceding or following it, and with every line ending in a newline. The paths should be printed using the same ordering rules as the last time you printed them (i.e., lexicographical ordering, as described above), though, of course, you will likely print fewer this time, since not every file will necessarily meet the search characteristic. If there were no interesting files, the program ends; there is no action to take. Now that we've narrowed down our search, it's time to take action on the files we found. The actions are to be taken on the files in the same order as you printed them previously. The program now reads a line of input that describes the action that will be taken on each interesting file. There are three different actions, and this line of input chooses one of them. o If this line of input contains the letter F by itself, print the first line of text from the file if it's a text file; print NOT TEXT if it is not. O If this line of input contains the letter D by itself, make a duplicate copy of the file and store it in the same directory where the original resides, but the copy should have .dup (short for "duplicate") appended to its filename. For example, if the interesting file is C:\pictures\boo.jpg, you would copy it to C:\pictures\boo.jpg.dup. . If the third line of the input contains the letter T by itself, "touch" the file, which means to modify its last modified timestamp to be the current date/time. If this line of input does not match one of the formats described above, print the word ERROR on a line by itself and repeat reading a line of input; continue until the input is valid. Once an action has been taken on all files, the program ends. O Your program will take input from the console in the following format. It should not prompt the user in any way. The intent here is not to write a user-friendly user interface; what you're actually doing is building a program that we can test automatically, so it's vital that your program reads inputs and writes outputs precisely as specified below. ● First, the program reads a line of input that specifies which files are eligible to be found. That can be specified in one of two ways: • The letter D, followed by a space, followed (on the rest of the line) by the path to a directory. In this case, all of the files in that directory will be under consideration, but no subdirectories (and no files in those subdirectories) will be. (You can think of the letter D here as standing for "directory.") o The letter R, followed by a space, followed (on the rest of the line) by the path to a directory. In this case, all of the files in that directory will be under consideration, along with all of the files in its subdirectories, all of the files in their subdirectories, and so on. (You can think of the letter R here as standing for "recursive.") o If this line of input does not follow this format, or if the directory specified does not exist, print the word ERROR on a line by itself and repeat reading this line of input; continue until the input is valid. Next, the program prints the paths to every file that is under consideration. Each path is printed on its own line, with no whitespace preceding or following it, and with every line ending in a newline. Note, also, that the order in which the files' paths are printed is relevant; you must print them in the following order: o First, the paths to all of the files in the directory are printed. These are printed in lexicographical order of the file's names. (More on lexicographical order a bit later, but note that this is the default way that strings are sorted.) • Next, if the files in subdirectories are being considered, the files in each of the subdirectories are printed according to the same ordering rules here, with all of the files in one subdirectory printed before any of the others, and with the subdirectories printed in lexicographical order of their names. ● Now that the program has displayed the paths of every file under consideration, it's time to narrow our search. The program now reads a line of input that describes the search characteristics that will be used to decide whether files are "interesting" and should have action taken on them. There are five different characteristics, and this line of input chooses one of them. . If this line of input is the letter A alone on a line, all of the files found in the previous step are considered interesting. O If this line of input begins with the letter N, the search will be for files whose names exactly match a particular name. The N will be followed by a space; after the space, the rest of the line will indicate the name of the files to be searched for. Note that filenames include extensions, so a search for boo would not find a file named boo.doc. ■ If this line of input begins with the letter E, the search will be for files whose names have a particular extension. The E will be followed by a space; after the space, the rest of the line will indicate the desired extension. For example, if the desired extension is py, all files whose names end in .py will be considered interesting. The desired extension may be specified with or without a dot preceding it (e.g., E .py or E py would mean the same thing in the input), and your search should behave the same either way. ■ Note, also, that there is a difference between what you might call a name ending and an extension. In our program, if the search is looking for files with the extension oc, a file named iliveinthe.oc would be found, but a file named invoice.doc would not. o If this line of input begins with the letter T, the search will be for text files that contain the given text. The T will be followed by a space; after the space, the rest of the line will indicate the text that the file should contain in order to be considered interesting. ■ For example, if this line of input reads T while True, any text file containing the text "while True" would be considered interesting. ▪ One thing to note is that not all files are text files, but that you can't determine that by their name or their extension. Any file that can be opened and read as a text file is considered a text file for our purposes here, regardless of its name. Any file that cannot be opened and read as a text file should be skipped (i.e., it is not considered interesting). o If this line of input begins with the character <, the search will be for files whose size, measured in bytes, is less than a specified threshold. The < will be followed by a space; after the space, the rest of the line will be a non-negative integer value specifying the size threshold. . For example, the input < 65536 means that files whose sizes are no more than 65,535 bytes (i.e., less than 65,536 bytes) will be considered interesting. If this line of input begins with the character >, the search will be for files whose size, measured in bytes, is greater than a specified threshold. The > will be followed by a space; after the space, the rest of the line will be a non-negative integer value specifying the size threshold. For example, the input > 2097151 means that files whose sizes are at least 2,097,152 bytes (i.e., greater than 2,097,151 bytes) will be considered interesting. If this line of input does not match one of the formats described above, print the word ERROR on a line by itself and repeat reading a line of input; continue until the input is valid. Note that it is not an error to specify a search characteristic that matches no files; it's only an error if this line of input is structurally invalid (i.e., it does not match one of the formats above). • ● ● Next, the program prints the paths to every file that is considered interesting, based on the search characteristic. Each path is printed on its own line, with no whitespace preceding or following it, and with every line ending in a newline. The paths should be printed using the same ordering rules as the last time you printed them (i.e., lexicographical ordering, as described above), though, of course, you will likely print fewer this time, since not every file will necessarily meet the search characteristic. If there were no interesting files, the program ends; there is no action to take. Now that we've narrowed down our search, it's time to take action on the files we found. The actions are to be taken on the files in the same order as you printed them previously. The program now reads a line of input that describes the action that will be taken on each interesting file. There are three different actions, and this line of input chooses one of them. o If this line of input contains the letter F by itself, print the first line of text from the file if it's a text file; print NOT TEXT if it is not. O If this line of input contains the letter D by itself, make a duplicate copy of the file and store it in the same directory where the original resides, but the copy should have .dup (short for "duplicate") appended to its filename. For example, if the interesting file is C:\pictures\boo.jpg, you would copy it to C:\pictures\boo.jpg.dup. . If the third line of the input contains the letter T by itself, "touch" the file, which means to modify its last modified timestamp to be the current date/time. If this line of input does not match one of the formats described above, print the word ERROR on a line by itself and repeat reading a line of input; continue until the input is valid. Once an action has been taken on all files, the program ends. O
Expert Answer:
Answer rating: 100% (QA)
Python program that takes input from the console in the following format D and outputs the paths to all of the files in the directory in lexicographical order import pathlib def readinput Reads the in... View the full answer
Related Book For
Principles Of Information Security
ISBN: 9780357506431
7th Edition
Authors: Michael E. Whitman, Herbert J. Mattord
Posted Date:
Students also viewed these computer network questions
-
Artyom, who works for Annushka's antique shop, forges Annushka's name ontwo checks, cashes the checks and deposits the funds into his own bank account. Artyom is overcome by his feeling of remorse,...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
You are required to write a Python program that will manage character (heroes and villain) information. Character (hero and villain) information will be stored in a text file that will be read in...
-
(8) (Non circular cylinder) A solid right (noncircular) cylinder has its base the R in the xy-plane and is bounded above by is 22-y + +5 5 * (x + y) dx dy paraboloid 2= x + y . The cylinder's volume....
-
Somnio, a start-up running shoe company in California, decided to start selling its products around the world from the very beginning. In general terms, name some of the challenges that a start-up...
-
Consider again the choice between outsourcing and in-house assembly of HomeNet discussed in Section 8.3 and analyzed in Table 8.6. Suppose, however, that the upfront cost to set up for in-house...
-
Meo Consulting, Inc., completed the following transactions during February 2010, its first month of operations: Requirements 1. Record transactions in the journal. Explanations are not required. 2....
-
Which portfolio is better diversified, one that contains stock in a dental supply company and a candy company or one that contains stock in a dental supply company and a dairy product company?
-
A car travelling at 35 mph suddenly collides with a concrete wall. The driver is wearing a seatbelt and is not seriously hurt. The passenger next to the driver does not have their seat belt on. Upon...
-
Obtain the Laplace transform of f (t) in Fig. 15.28 . f(t) A 15 1 2 3 4 t
-
Giorgio's cost of goods sold was $9,493 million, with an inventory of $2,161 million and an average inventory of $2,037 million. Required What is the inventory turnover rate?
-
The Jamaica Company manufactures a product in a single process. The following information is available: Beginning WIP Inventory Input Material Direct Labour Cost Incurred Manufacturing Overhead...
-
Barley Hopp, Incorporated, manufactures custom-ordered commemorative beer steins. Its standard cost information follows: Standard Unit Standard Quantity Standard Price (Rate) Direct materials (clay)...
-
A retailer purchased eggs at $2.80 per dozen and sold the eggs at 3 eggs for $0.90. What was the retailer's gross profit from purchasing and selling 5 dozen eggs? (1 dozen eggs = 12 eggs)
-
On January 5 , 2 0 2 1 , Singer Company sells 1 5 , 0 0 0 shares of $ 1 par value stock for $ 2 0 per share. They repurchase 1 , 0 0 0 of those shares at $ 2 1 per share on November 1 5 , 2 0 2 1 ....
-
ACME Company manufactures televisions. The company estimated there will be 4 7 , 7 0 0 units in inventory at the beginning of December 2 0 1 9 . ACME wants to have half of that amount in its...
-
You have been offered a 30-year mortgage at 6.00% for $300,000. The original loan to value is 90% and thus the loan requires PMI. The loan requires PMI payments of $120 per month for 100 payments....
-
Representative data read from a plot that appeared in the paper Effect of Cattle Treading on Erosion from Hill Pasture: Modeling Concepts and Analysis of Rainfall Simulator Data (Australian Journal...
-
I. Relate that the configuration of firewall policies can be complex and difficult. Explain how each configuration rule must be carefully crafted, debugged, tested, and sorted. II. Emphasize that...
-
Analyze the three methods that often dominate detection methods and evaluate network traffic: signature-based detection, anomaly-based detection, and stateful protocol analysis.
-
I. Explain that packet-filtering firewalls examine the header information of data packets that come into a network. Apply Figure 8-7 as a visual illustration of a standard IPv4 packet structure. II....
-
Explain the difference between dollar-value estimation and hypothesis testing in audit sampling. Which of the two is more common in auditing?
-
Under what condition is difference estimation more appropriate than ratio estimation?
-
Identify the relative advantages and disadvantages of probability-proportional-tosize sampling.
Study smarter with the SolutionInn App