[SOLVED] CMPE230-Project 2

30.99 $

Category:

Description

5/5 - (1 vote)

Write a Python program that can be invoked with the following options and arguments:

          duplicates  < -c <command> | -p >   [-f | -d]  [“…”] [<dir1> <dir2> ..]

The duplicates program will traverse the directories and look for files or directories that are exact duplicates of each other. It will then carry out an action on the files or directories in question. The explanations of the options and arguments are given in the following table:

< -c <command> | -p >                        If -c is given, a command  will be passed the list

of files/directories which are duplicates. If -p is given , then the duplicates will be printed (a new line should be printed between the sets of duplicates)

[-f | -d ]                                   -f means look for duplicate files, -d means look

for duplicate directories. The default is duplicate files.

[ “…”]                                     Consider only the filenames or directory names

that match the Python pattern given in “…“. The default is all files  or all directories

[<dir1> <dir2> ..]                           The list of directories to traverse (note that the

directories will be traversed recursively,  i.e. directories and their subdirectories and their subdirectories etc. etc.).  The default is current directory.

Note:

  • Assume that directory hierarchy forms a tree.
  • Duplicate will mean the contents are exactly the same (note that the names can be different). You can take sha256 hashes of files and compare the hashes in order to locate duplicate files and directories.
  • To locate duplicate directories, you can use hash trees.
  • You can use python2 or python3.