I would like to write a Perl code that will do a kind of smart copy between directories.
Can you please help me to write this code in Perl?
The directory structure is like this:
What I want to do is to copy the files in the bin directories
of productA, productB and productC to the bin directory in the e directory
The same way, I want to copy the files in the lib directories
of productA, productB and productC to the lib directory in the e directory
Before actually copying the files, the code should check if there are any files that conflicts (name conflict) between all the products (This example has 3 products A, B and C but it can be more than three. Also, anything other than bin or lib in e directory means it is a product. Bin adn Lib directories in the e directory are the destination directories). then the code should prompt to the user and ask if he wants to copy. If the user says yes, then it should start copying otherwise it should not do anything. The code should prompt to the user whether there is a conflict or not.
The sudo code is like this:
Example 1 with a conflicting file name:
Ask the input directory from the user (with getoptions)
Loop through all the files in all the child directories of the given directory and push them in to an array.
Loop through all the files in all the child directories of the directories that are in the same level as the input directory and push them to an array. (Let's say if the input is [b]/a/b/c/d/e/productA[/b] then loop through the productb and productC directories. Do not loop through bin and lib in e directory because it is not a product. It is a destination.)
Check if there are any name conflicts between the two arrays.
Tell the user if there are any conflicts and print this information on the screen and ask if he wants to continue. (even if there is no conflict I would like to prompt to the user to say yes or not)
If the user says "no" then do not start copying and exit.
If the user says "yes" then start copying files from the bin directory of the input directory to the bin directory in the "e" directory. And do the same copy for the "lib" directory.
The code should overwrite to the files in the destination directory.
The code should be able to detect that there is a name conflict in the "lib" directories of productA and productB. and it should tell the user that "/a/b/c/d/e/productB/lib/f
l" causes conflict. And asks the users if he wants to continue.
If the user says no then it should not copy anything.
Example 2 wit no conflicting file name:
Even though there is no conflict in the file names between the products, the user will be prompted and if he says yes then it will copy the files otherwise it will not do anything.