Copying files across folders using Perl on Windows
Posted on 2004-11-13
I want to accomplish the following using Perl on a Windows XP machine.
Consider the following folder/file structure:
folder fo1 has files fi1, fi2, and fi3
folder fo2 has files fi3, fi4, and fi5
I want to copy and store all files in fo2. Think of fo1 as a temp folder. If the file names are unique, there is no problem. However, if there are overalpping file names, I want to make a decision. In the example above, here is how fo2 will look like AFTER the script has been run: fi1, fi2, fi3, fi4, and fi5. Folder fo1 will be empy. However, when file fi3 is moved from fo1 to fo2, a check should be done to determine if the two version of fi3 are the same. If the fo1.fi3 and fo2.fi3 are identical, fo1.fi3 should be deleted as the file fo2.fi3 is already there. However, if fo1.fi3 and fo2.fi3 are DIFFERENT, first of all fo2.fi3 should be left alone. fo1.fi3 should be RENAMED to a filename that does NOT exist in folder fo2 and THEN moved to folder fo2. The renaming can be a simple scheme (e.g. append _1, or _2 to the end of the filename).
Does this clarify what I am trying to do ?
In reality, I have hundreds of files spread across tens of folder.